Search in sources :

Example 31 with DerOutputStream

use of org.mozilla.jss.netscape.security.util.DerOutputStream in project jss by dogtagpki.

the class PresenceServerExtension method encode.

@Override
public void encode(OutputStream out) throws CertificateException, IOException {
    DerOutputStream dos = new DerOutputStream();
    super.encode(dos);
    out.write(dos.toByteArray());
}
Also used : DerOutputStream(org.mozilla.jss.netscape.security.util.DerOutputStream)

Example 32 with DerOutputStream

use of org.mozilla.jss.netscape.security.util.DerOutputStream in project jss by dogtagpki.

the class PKCS10 method encodeAndSign.

/**
 * Create the signed certificate request. This will later be
 * retrieved in either string or binary format.
 *
 * @param requester identifies the signer (by X.500 name)
 *            and provides the private key used to sign.
 * @exception IOException on errors.
 * @exception CertificateException on certificate handling errors.
 * @exception SignatureException on signature handling errors.
 */
public void encodeAndSign(X500Signer requester) throws CertificateException, IOException, SignatureException {
    DerOutputStream out, scratch;
    byte[] certificateRequestInfo;
    byte[] sig;
    if (certificateRequest != null)
        throw new SignatureException("request is already signed");
    subject = requester.getSigner();
    /*
         * Encode cert request info, wrap in a sequence for signing
         */
    scratch = new DerOutputStream();
    // version zero
    scratch.putInteger(new BigInt(0));
    // X.500 name
    subject.encode(scratch);
    // public key
    subjectPublicKeyInfo.encode(scratch);
    attributeSet.encode(scratch);
    out = new DerOutputStream();
    // wrap it!
    out.write(DerValue.tag_Sequence, scratch);
    certificateRequestInfo = out.toByteArray();
    scratch = out;
    /*
         * Sign it ...
         */
    requester.update(certificateRequestInfo, 0, certificateRequestInfo.length);
    sig = requester.sign();
    /*
         * Build guts of SIGNED macro
         */
    // sig algorithm
    requester.getAlgorithmId().encode(scratch);
    // sig
    scratch.putBitString(sig);
    /*
         * Wrap those guts in a sequence
         */
    out = new DerOutputStream();
    out.write(DerValue.tag_Sequence, scratch);
    certificateRequest = out.toByteArray();
}
Also used : DerOutputStream(org.mozilla.jss.netscape.security.util.DerOutputStream) BigInt(org.mozilla.jss.netscape.security.util.BigInt) SignatureException(java.security.SignatureException)

Example 33 with DerOutputStream

use of org.mozilla.jss.netscape.security.util.DerOutputStream in project jss by dogtagpki.

the class CertificateScopeEntry method encode.

public void encode(DerOutputStream out) throws IOException {
    DerOutputStream tmp = new DerOutputStream();
    mGn.encode(tmp);
    if (mPort != null) {
        tmp.putInteger(mPort);
    }
    out.write(DerValue.tag_Sequence, tmp);
}
Also used : DerOutputStream(org.mozilla.jss.netscape.security.util.DerOutputStream)

Example 34 with DerOutputStream

use of org.mozilla.jss.netscape.security.util.DerOutputStream in project jss by dogtagpki.

the class ExtendedKeyUsageExtension method encodeExtValue.

private void encodeExtValue() throws IOException {
    DerOutputStream out = new DerOutputStream();
    DerOutputStream temp = new DerOutputStream();
    if (!oidSet.isEmpty()) {
        Enumeration<ObjectIdentifier> oidList = oidSet.elements();
        try {
            while (oidList.hasMoreElements()) {
                temp.putOID(oidList.nextElement());
            }
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
    try {
        out.write(DerValue.tag_Sequence, temp);
    } catch (IOException ex) {
    } finally {
        out.close();
    }
    extensionValue = out.toByteArray();
}
Also used : DerOutputStream(org.mozilla.jss.netscape.security.util.DerOutputStream) IOException(java.io.IOException) ObjectIdentifier(org.mozilla.jss.netscape.security.util.ObjectIdentifier)

Example 35 with DerOutputStream

use of org.mozilla.jss.netscape.security.util.DerOutputStream in project jss by dogtagpki.

the class ExtendedKeyUsageExtension method encode.

@Override
public void encode(OutputStream out) throws CertificateException, IOException {
    if (mCached == null) {
        DerOutputStream temp = new DerOutputStream();
        encode(temp);
    }
    out.write(mCached);
}
Also used : DerOutputStream(org.mozilla.jss.netscape.security.util.DerOutputStream)

Aggregations

DerOutputStream (org.mozilla.jss.netscape.security.util.DerOutputStream)141 IOException (java.io.IOException)37 BigInt (org.mozilla.jss.netscape.security.util.BigInt)13 DerValue (org.mozilla.jss.netscape.security.util.DerValue)8 ObjectIdentifier (org.mozilla.jss.netscape.security.util.ObjectIdentifier)8 CRLException (java.security.cert.CRLException)7 CertificateException (java.security.cert.CertificateException)7 InvalidKeyException (java.security.InvalidKeyException)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 ANY (org.mozilla.jss.asn1.ANY)5 InvalidBERException (org.mozilla.jss.asn1.InvalidBERException)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 KeyFactory (java.security.KeyFactory)3 SignatureException (java.security.SignatureException)3 CertificateEncodingException (java.security.cert.CertificateEncodingException)3 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)3 NoSuchProviderException (java.security.NoSuchProviderException)2 Provider (java.security.Provider)2 PublicKey (java.security.PublicKey)2