Search in sources :

Example 26 with Sequence

use of com.google.showcase.v1beta1.Sequence in project jss by dogtagpki.

the class SafeBag method encode.

@Override
public void encode(Tag implicitTag, OutputStream ostream) throws IOException {
    SEQUENCE seq = new SEQUENCE();
    seq.addElement(bagType);
    seq.addElement(new EXPLICIT(new Tag(0), bagContent));
    if (bagAttributes != null) {
        seq.addElement(bagAttributes);
    }
    seq.encode(implicitTag, ostream);
}
Also used : SEQUENCE(org.mozilla.jss.asn1.SEQUENCE) Tag(org.mozilla.jss.asn1.Tag) EXPLICIT(org.mozilla.jss.asn1.EXPLICIT)

Example 27 with Sequence

use of com.google.showcase.v1beta1.Sequence in project jss by dogtagpki.

the class SignerInfo method encode.

@Override
public void encode(Tag tag, OutputStream ostream) throws IOException {
    SEQUENCE sequence = new SEQUENCE();
    sequence.addElement(version);
    sequence.addElement(signerIdentifier);
    sequence.addElement(digestAlgorithm);
    if (signedAttributes != null) {
        sequence.addElement(new Tag(0), signedAttributes);
    }
    sequence.addElement(digestEncryptionAlgorithm);
    sequence.addElement(encryptedDigest);
    if (unsignedAttributes != null) {
        sequence.addElement(new Tag(1), unsignedAttributes);
    }
    sequence.encode(tag, ostream);
}
Also used : SEQUENCE(org.mozilla.jss.asn1.SEQUENCE) Tag(org.mozilla.jss.asn1.Tag)

Example 28 with Sequence

use of com.google.showcase.v1beta1.Sequence in project jss by dogtagpki.

the class SignerInfo method verifyWithoutSignedAttributes.

/**
 * Verifies that the message digest passed in, when encrypted with the
 * given public key, matches the encrypted digest in the SignerInfo.
 */
private void verifyWithoutSignedAttributes(byte[] messageDigest, OBJECT_IDENTIFIER contentType, PublicKey pubkey) throws NotInitializedException, NoSuchAlgorithmException, InvalidKeyException, TokenException, SignatureException {
    if (!contentType.equals(ContentInfo.DATA)) {
        // to go into signedAttributes.
        throw new SignatureException("Content-Type is not DATA, but there are" + " no signed attributes");
    }
    SignatureAlgorithm sigAlg = SignatureAlgorithm.fromOID(digestEncryptionAlgorithm.getOID());
    CryptoToken token = CryptoManager.getInstance().getInternalCryptoToken();
    Signature sig;
    byte[] toBeVerified;
    if (sigAlg.getRawAlg() == SignatureAlgorithm.RSASignature) {
        // create DigestInfo structure
        SEQUENCE digestInfo = createDigestInfo(messageDigest, false);
        toBeVerified = ASN1Util.encode(digestInfo);
        sig = token.getSignatureContext(sigAlg.getRawAlg());
    } else {
        toBeVerified = messageDigest;
        sig = token.getSignatureContext(sigAlg);
    }
    sig.initVerify(pubkey);
    sig.update(toBeVerified);
    if (sig.verify(encryptedDigest.toByteArray())) {
        // success
        return;
    } else {
        throw new SignatureException("Encrypted message digest parameter does not " + "match encrypted digest in SignerInfo");
    }
}
Also used : CryptoToken(org.mozilla.jss.crypto.CryptoToken) Signature(org.mozilla.jss.crypto.Signature) SEQUENCE(org.mozilla.jss.asn1.SEQUENCE) SignatureAlgorithm(org.mozilla.jss.crypto.SignatureAlgorithm) SignatureException(java.security.SignatureException)

Example 29 with Sequence

use of com.google.showcase.v1beta1.Sequence in project jss by dogtagpki.

the class MacData method encode.

@Override
public void encode(Tag implicitTag, OutputStream ostream) throws IOException {
    SEQUENCE seq = new SEQUENCE();
    seq.addElement(mac);
    seq.addElement(macSalt);
    if (!macIterationCount.equals(new INTEGER(DEFAULT_ITERATIONS))) {
        // 1 is the default, only include this element if it is not
        // the default
        seq.addElement(macIterationCount);
    }
    seq.encode(implicitTag, ostream);
}
Also used : SEQUENCE(org.mozilla.jss.asn1.SEQUENCE) INTEGER(org.mozilla.jss.asn1.INTEGER)

Example 30 with Sequence

use of com.google.showcase.v1beta1.Sequence in project jss by dogtagpki.

the class CertRepContent method encode.

@Override
public void encode(Tag implicitTag, OutputStream ostream) throws IOException {
    SEQUENCE encoding = new SEQUENCE();
    // create sequence of certificates
    if (caPubs != null) {
        SEQUENCE certs = new SEQUENCE();
        for (int i = 0; i < caPubs.length; i++) {
            certs.addElement(new ANY(SEQUENCE.TAG, caPubs[i]));
        }
        encoding.addElement(new Tag(1), certs);
    }
    encoding.addElement(response);
    encoding.encode(implicitTag, ostream);
}
Also used : SEQUENCE(org.mozilla.jss.asn1.SEQUENCE) Tag(org.mozilla.jss.asn1.Tag) ANY(org.mozilla.jss.asn1.ANY)

Aggregations

SEQUENCE (org.mozilla.jss.asn1.SEQUENCE)50 OCTET_STRING (org.mozilla.jss.asn1.OCTET_STRING)16 Sequence (org.sbolstandard.core2.Sequence)11 SET (org.mozilla.jss.asn1.SET)9 ANY (org.mozilla.jss.asn1.ANY)8 InvalidBERException (org.mozilla.jss.asn1.InvalidBERException)8 OBJECT_IDENTIFIER (org.mozilla.jss.asn1.OBJECT_IDENTIFIER)8 URI (java.net.URI)7 BMPString (org.mozilla.jss.asn1.BMPString)7 CryptoToken (org.mozilla.jss.crypto.CryptoToken)7 ASN1Value (org.mozilla.jss.asn1.ASN1Value)6 INTEGER (org.mozilla.jss.asn1.INTEGER)6 AuthenticatedSafes (org.mozilla.jss.pkcs12.AuthenticatedSafes)6 FileOutputStream (java.io.FileOutputStream)5 IOException (java.io.IOException)5 SignatureException (java.security.SignatureException)5 EXPLICIT (org.mozilla.jss.asn1.EXPLICIT)5 SafeBag (org.mozilla.jss.pkcs12.SafeBag)5 Certificate (org.mozilla.jss.pkix.cert.Certificate)5 ComponentDefinition (org.sbolstandard.core2.ComponentDefinition)5