public static CertificationRequestInfo getInstance( Object obj) { if (obj instanceof CertificationRequestInfo) { return (CertificationRequestInfo)obj; } else if (obj != null) { return new CertificationRequestInfo(ASN1Sequence.getInstance(obj)); } return null; }
/** * Return the SubjectPublicKeyInfo describing the public key this request is carrying. * * @return the public key ASN.1 structure contained in the request. */ public SubjectPublicKeyInfo getSubjectPublicKeyInfo() { return certificationRequest.getCertificationRequestInfo().getSubjectPublicKeyInfo(); }
/** * Return the subject on this request. * * @return the X500Name representing the request's subject. */ public X500Name getSubject() { return X500Name.getInstance(certificationRequest.getCertificationRequestInfo().getSubject()); }
this.reqInfo = new CertificationRequestInfo(subject, SubjectPublicKeyInfo.getInstance(seq), attributes); sig.update(reqInfo.getEncoded(ASN1Encoding.DER));
public byte[] generateCSR (X500Name subject, PublicKey publicKey, String signatureAlgorithm) throws Exception{ //Create the unsigned CSR CertificationRequestInfo info = new CertificationRequestInfo( x500name, SubjectPublicKeyInfo.getInstance(publicKey.getEncoded()),new DERSet()); //The CSR bytes to be signed byte dataToSign[] = info.getEncoded(ASN1Encoding.DER); //Send the CSR to the card byte signedData[] = signOnJavaCard (dataToSign,signatureAlgorithm); //Build the signed CSR AlgorithmIdentifier sigAlgId = new DefaultSignatureAlgorithmIdentifierFinder().find(signatureAlgorithm); PKCS10CertificationRequest csr = new PKCS10CertificationRequest( new CertificationRequest(info, sigAlgId, new DERBitString(signedData))); byte signedCSR = csr.getEncoded(); //Verify signature validity ContentVerifierProvider verifier = new JcaContentVerifierProviderBuilder().setProvider(new BouncyCastleProvider()).build(publicKey); boolean valid = csr.isSignatureValid(verifier); return signedCSR; }
/** * Return an array of attributes matching the passed in type OID. * * @param type the type of the attribute being looked for. * @return an array of Attribute of the requested type, zero length if none present. */ public Attribute[] getAttributes(ASN1ObjectIdentifier type) { ASN1Set attrSet = certificationRequest.getCertificationRequestInfo().getAttributes(); if (attrSet == null) { return EMPTY_ARRAY; } List list = new ArrayList(); for (int i = 0; i != attrSet.size(); i++) { Attribute attr = Attribute.getInstance(attrSet.getObjectAt(i)); if (attr.getAttrType().equals(type)) { list.add(attr); } } if (list.size() == 0) { return EMPTY_ARRAY; } return (Attribute[])list.toArray(new Attribute[list.size()]); }
/** * @deprecated use getInstance() */ public CertificationRequest( ASN1Sequence seq) { reqInfo = CertificationRequestInfo.getInstance(seq.getObjectAt(0)); sigAlgId = AlgorithmIdentifier.getInstance(seq.getObjectAt(1)); sigBits = (DERBitString)seq.getObjectAt(2); }
this.reqInfo = new CertificationRequestInfo(subject, new SubjectPublicKeyInfo(seq), attributes); sig.update(reqInfo.getEncoded(ASN1Encoding.DER));
/** * Validate the signature on the PKCS10 certification request in this holder. * * @param verifierProvider a ContentVerifierProvider that can generate a verifier for the signature. * @return true if the signature is valid, false otherwise. * @throws PKCSException if the signature cannot be processed or is inappropriate. */ public boolean isSignatureValid(ContentVerifierProvider verifierProvider) throws PKCSException { CertificationRequestInfo requestInfo = certificationRequest.getCertificationRequestInfo(); ContentVerifier verifier; try { verifier = verifierProvider.get(certificationRequest.getSignatureAlgorithm()); OutputStream sOut = verifier.getOutputStream(); sOut.write(requestInfo.getEncoded(ASN1Encoding.DER)); sOut.close(); } catch (Exception e) { throw new PKCSException("unable to process signature: " + e.getMessage(), e); } return verifier.verify(this.getSignature()); }
/** * Return an array of attributes matching the passed in type OID. * * @param type the type of the attribute being looked for. * @return an array of Attribute of the requested type, zero length if none present. */ public Attribute[] getAttributes(ASN1ObjectIdentifier type) { ASN1Set attrSet = certificationRequest.getCertificationRequestInfo().getAttributes(); if (attrSet == null) { return EMPTY_ARRAY; } List list = new ArrayList(); for (int i = 0; i != attrSet.size(); i++) { Attribute attr = Attribute.getInstance(attrSet.getObjectAt(i)); if (attr.getAttrType().equals(type)) { list.add(attr); } } if (list.size() == 0) { return EMPTY_ARRAY; } return (Attribute[])list.toArray(new Attribute[list.size()]); }
public CertificationRequest( ASN1Sequence seq) { reqInfo = CertificationRequestInfo.getInstance(seq.getObjectAt(0)); sigAlgId = AlgorithmIdentifier.getInstance(seq.getObjectAt(1)); sigBits = (DERBitString)seq.getObjectAt(2); }
info = new CertificationRequestInfo(subject, publicKeyInfo, null); info = new CertificationRequestInfo(subject, publicKeyInfo, new DERSet()); info = new CertificationRequestInfo(subject, publicKeyInfo, new DERSet(v)); sOut.write(info.getEncoded(ASN1Encoding.DER));
sig.update(reqInfo.getEncoded(ASN1Encoding.DER));
public static CertificationRequestInfo getInstance( Object obj) { if (obj instanceof CertificationRequestInfo) { return (CertificationRequestInfo)obj; } else if (obj != null) { return new CertificationRequestInfo(ASN1Sequence.getInstance(obj)); } return null; }
/** * Return the SubjectPublicKeyInfo describing the public key this request is carrying. * * @return the public key ASN.1 structure contained in the request. */ public SubjectPublicKeyInfo getSubjectPublicKeyInfo() { return certificationRequest.getCertificationRequestInfo().getSubjectPublicKeyInfo(); }
/** * Return the attributes, if any associated with this request. * * @return an array of Attribute, zero length if none present. */ public Attribute[] getAttributes() { ASN1Set attrSet = certificationRequest.getCertificationRequestInfo().getAttributes(); if (attrSet == null) { return EMPTY_ARRAY; } Attribute[] attrs = new Attribute[attrSet.size()]; for (int i = 0; i != attrSet.size(); i++) { attrs[i] = Attribute.getInstance(attrSet.getObjectAt(i)); } return attrs; }
/** * Return the subject on this request. * * @return the X500Name representing the request's subject. */ public X500Name getSubject() { return X500Name.getInstance(certificationRequest.getCertificationRequestInfo().getSubject()); }
info = new CertificationRequestInfo(subject, publicKeyInfo, null); info = new CertificationRequestInfo(subject, publicKeyInfo, new DERSet()); info = new CertificationRequestInfo(subject, publicKeyInfo, new DERSet(v)); sOut.write(info.getEncoded(ASN1Encoding.DER));
/** * Validate the signature on the PKCS10 certification request in this holder. * * @param verifierProvider a ContentVerifierProvider that can generate a verifier for the signature. * @return true if the signature is valid, false otherwise. * @throws PKCSException if the signature cannot be processed or is inappropriate. */ public boolean isSignatureValid(ContentVerifierProvider verifierProvider) throws PKCSException { CertificationRequestInfo requestInfo = certificationRequest.getCertificationRequestInfo(); ContentVerifier verifier; try { verifier = verifierProvider.get(certificationRequest.getSignatureAlgorithm()); OutputStream sOut = verifier.getOutputStream(); sOut.write(requestInfo.getEncoded(ASN1Encoding.DER)); sOut.close(); } catch (Exception e) { throw new PKCSException("unable to process signature: " + e.getMessage(), e); } return verifier.verify(this.getSignature()); }
InvalidKeyException SubjectPublicKeyInfo subjectPKInfo = reqInfo.getSubjectPublicKeyInfo(); X509EncodedKeySpec xspec = new X509EncodedKeySpec(new DERBitString(subjectPKInfo).getBytes()); AlgorithmIdentifier keyAlg = subjectPKInfo.getAlgorithmId();