/** * Converts, if possible, a key specification into a {@link BCMcElieceCCA2PrivateKey}. Currently, * the following key specifications are supported: {@link McElieceCCA2PrivateKeySpec}, {@link * PKCS8EncodedKeySpec}. * * @param keySpec the key specification * @return the McEliece CCA2 private key * @throws InvalidKeySpecException if the KeySpec is not supported. */ public PrivateKey generatePrivate(KeySpec keySpec) throws InvalidKeySpecException { if (keySpec instanceof McElieceCCA2PrivateKeySpec) { return new BCMcElieceCCA2PrivateKey((McElieceCCA2PrivateKeySpec) keySpec); } else if (keySpec instanceof PKCS8EncodedKeySpec) { // get the DER-encoded Key according to PKCS#8 from the spec byte[] encKey = ((PKCS8EncodedKeySpec) keySpec).getEncoded(); // decode the PKCS#8 data structure to the pki object PrivateKeyInfo pki; try { pki = PrivateKeyInfo.getInstance(ASN1Primitive.fromByteArray(encKey)); } catch (IOException e) { throw new InvalidKeySpecException("Unable to decode PKCS8EncodedKeySpec: " + e); } try { // get the inner type inside the BIT STRING ASN1Primitive innerType = pki.parsePrivateKey().toASN1Primitive(); // build and return the actual key ASN1Sequence privKey = (ASN1Sequence) innerType; // decode oidString (but we don't need it right now) String oidString = ((ASN1ObjectIdentifier) privKey.getObjectAt(0)).toString(); // decode <n> BigInteger bigN = ((ASN1Integer) privKey.getObjectAt(1)).getValue(); int n = bigN.intValue(); // decode <k> BigInteger bigK = ((ASN1Integer) privKey.getObjectAt(2)).getValue(); int k = bigK.intValue(); // decode <fieldPoly> byte[] encFieldPoly = ((ASN1OctetString) privKey.getObjectAt(3)).getOctets(); // decode <goppaPoly> byte[] encGoppaPoly = ((ASN1OctetString) privKey.getObjectAt(4)).getOctets(); // decode <p> byte[] encP = ((ASN1OctetString) privKey.getObjectAt(5)).getOctets(); // decode <h> byte[] encH = ((ASN1OctetString) privKey.getObjectAt(6)).getOctets(); // decode <qInv> ASN1Sequence qSeq = (ASN1Sequence) privKey.getObjectAt(7); byte[][] encQInv = new byte[qSeq.size()][]; for (int i = 0; i < qSeq.size(); i++) { encQInv[i] = ((ASN1OctetString) qSeq.getObjectAt(i)).getOctets(); } return new BCMcElieceCCA2PrivateKey( new McElieceCCA2PrivateKeySpec( OID, n, k, encFieldPoly, encGoppaPoly, encP, encH, encQInv)); } catch (IOException cce) { throw new InvalidKeySpecException("Unable to decode PKCS8EncodedKeySpec."); } } throw new InvalidKeySpecException("Unsupported key specification: " + keySpec.getClass() + "."); }
public GeneralSubtree(ASN1Sequence seq) { base = GeneralName.getInstance(seq.getObjectAt(0)); switch (seq.size()) { case 1: break; case 2: ASN1TaggedObject o = ASN1TaggedObject.getInstance(seq.getObjectAt(1)); switch (o.getTagNo()) { case 0: minimum = DERInteger.getInstance(o, false); break; case 1: maximum = DERInteger.getInstance(o, false); break; default: throw new IllegalArgumentException("Bad tag number: " + o.getTagNo()); } break; case 3: minimum = DERInteger.getInstance(ASN1TaggedObject.getInstance(seq.getObjectAt(1))); maximum = DERInteger.getInstance(ASN1TaggedObject.getInstance(seq.getObjectAt(2))); break; default: throw new IllegalArgumentException("Bad sequence size: " + seq.size()); } }
/** * Return the attributes, if any associated with this request. * * @return an array of Attribute, zero length if none present. */ public Attribute[] getAttributes() { ASN1Sequence seq = attrCert.getAcinfo().getAttributes(); Attribute[] attrs = new Attribute[seq.size()]; for (int i = 0; i != seq.size(); i++) { attrs[i] = Attribute.getInstance(seq.getObjectAt(i)); } return attrs; }
public X509Attribute[] getAttributes() { ASN1Sequence seq = cert.getAcinfo().getAttributes(); X509Attribute[] attrs = new X509Attribute[seq.size()]; for (int i = 0; i != seq.size(); i++) { attrs[i] = new X509Attribute((ASN1Encodable) seq.getObjectAt(i)); } return attrs; }
/** * Reads the value of the <code>ExtendedKeyUsage</code> extension field of the certificate. * * @return List of supported extended key usages or null if extension is not defined. */ public List<KeyPurposeId> readExtendedKeyUsage() { final ASN1Encodable data = read(ExtensionType.ExtendedKeyUsage); if (data == null) { return null; } final ASN1Sequence sequence = ASN1Sequence.getInstance(data); final List<KeyPurposeId> list = new ArrayList<>(sequence.size()); for (int i = 0; i < sequence.size(); i++) { list.add(KeyPurposeId.getInstance(sequence.getObjectAt(i))); } return list; }
/** * Reads the value of the <code>CRLDistributionPoints</code> extension field of the certificate. * * @return List of CRL distribution points or null if extension is not defined. */ public List<DistributionPoint> readCRLDistributionPoints() { final ASN1Encodable data = read(ExtensionType.CRLDistributionPoints); if (data == null) { return null; } final ASN1Sequence sequence = ASN1Sequence.getInstance(data); final List<DistributionPoint> list = new ArrayList<>(sequence.size()); for (int i = 0; i < sequence.size(); i++) { list.add(DistributionPoint.getInstance(sequence.getObjectAt(i))); } return list; }
/** * Reads the value of the <code>CertificatePolicies</code> extension field of the certificate. * * @return List of certificate policies defined on certificate or null if the certificate does not * define the field. */ public List<PolicyInformation> readCertificatePolicies() { final ASN1Encodable data = read(ExtensionType.CertificatePolicies); if (data == null) { return null; } final ASN1Sequence sequence = ASN1Sequence.getInstance(data); final List<PolicyInformation> list = new ArrayList<>(sequence.size()); for (int i = 0; i < sequence.size(); i++) { list.add(PolicyInformation.getInstance(sequence.getObjectAt(i))); } return list; }
/** * Reads the value of the <code>AuthorityInformationAccess</code> extension field of the * certificate. * * @return List of access descriptions or null if extension is not defined. */ public List<AccessDescription> readAuthorityInformationAccess() { final ASN1Encodable data = read(ExtensionType.AuthorityInformationAccess); if (data == null) { return null; } final ASN1Sequence sequence = ASN1Sequence.getInstance(data); final List<AccessDescription> list = new ArrayList<>(sequence.size()); for (int i = 0; i < sequence.size(); i++) { list.add(AccessDescription.getInstance(sequence.getObjectAt(i))); } return list; }
/** * Creates a new <code>UserNotice</code> instance. * * <p>Useful from reconstructing a <code>UserNotice</code> instance from its encodable/encoded * form. * * @param as an <code>ASN1Sequence</code> value obtained from either calling @{link * toASN1Object()} for a <code>UserNotice</code> instance or from parsing it from a * DER-encoded stream. */ public UserNotice(ASN1Sequence as) { if (as.size() == 2) { noticeRef = NoticeReference.getInstance(as.getObjectAt(0)); explicitText = DisplayText.getInstance(as.getObjectAt(1)); } else if (as.size() == 1) { if (as.getObjectAt(0).getDERObject() instanceof ASN1Sequence) { noticeRef = NoticeReference.getInstance(as.getObjectAt(0)); } else { explicitText = DisplayText.getInstance(as.getObjectAt(0)); } } else { throw new IllegalArgumentException("Bad sequence size: " + as.size()); } }
private CscaMasterList(ASN1Sequence seq) { if (seq == null || seq.size() == 0) { throw new IllegalArgumentException("null or empty sequence passed."); } if (seq.size() != 2) { throw new IllegalArgumentException("Incorrect sequence size: " + seq.size()); } version = DERInteger.getInstance(seq.getObjectAt(0)); ASN1Set certSet = ASN1Set.getInstance(seq.getObjectAt(1)); certList = new X509CertificateStructure[certSet.size()]; for (int i = 0; i < certList.length; i++) { certList[i] = X509CertificateStructure.getInstance(certSet.getObjectAt(i)); } }
public VomsAttributeCertificateInfo(final ASN1Sequence seq) throws ProblemException { super(seq); ASN1Sequence attributes = getAttributes(); for (int i = 0; i < attributes.size(); i++) { ASN1Sequence attribute = (ASN1Sequence) attributes.getObjectAt(i); DERObjectIdentifier id = (DERObjectIdentifier) attribute.getObjectAt(0); if (VomsCredentialInfo.VOMS_ATTR_OID.equals(id.getId())) { DERSet set = (DERSet) attribute.getObjectAt(1); for (int j = 0; j < set.size(); j++) { IetfAttrSyntax attr = new IetfAttrSyntax((ASN1Sequence) set.getObjectAt(j)); ASN1Sequence paSeq = (ASN1Sequence) attr.getPolicyAuthority().getDERObject(); GeneralName paGName = GeneralName.getInstance(paSeq.getObjectAt(0)); String paString = ((DERIA5String) paGName.getName()).getString(); int sep = paString.indexOf("://"); // $NON-NLS-1$ if (sep != -1) { this.voNames.add(paString.substring(0, sep)); } for (Object attrValue : attr.getValues()) { String fqanString = new String(((ASN1OctetString) attrValue).getOctets()); this.fqans.add(FullyQualifiedAttributeName.getFqan(fqanString)); } } } } }
private ResponseData(ASN1Sequence seq) { int index = 0; if (seq.getObjectAt(0) instanceof ASN1TaggedObject) { ASN1TaggedObject o = (ASN1TaggedObject) seq.getObjectAt(0); if (o.getTagNo() == 0) { this.versionPresent = true; this.version = ASN1Integer.getInstance((ASN1TaggedObject) seq.getObjectAt(0), true); index++; } else { this.version = V1; } } else { this.version = V1; } this.responderID = ResponderID.getInstance(seq.getObjectAt(index++)); this.producedAt = (DERGeneralizedTime) seq.getObjectAt(index++); this.responses = (ASN1Sequence) seq.getObjectAt(index++); if (seq.size() > index) { this.responseExtensions = Extensions.getInstance((ASN1TaggedObject) seq.getObjectAt(index), true); } }
public IDEACBCPar(ASN1Sequence seq) { if (seq.size() == 1) { iv = (ASN1OctetString) seq.getObjectAt(0); } else { iv = null; } }
/** * Constructor from ASN1Sequence * * <p>the principal will be a list of constructed sets, each containing an (OID, String) pair. */ public X509Name(ASN1Sequence seq) { this.seq = seq; Enumeration e = seq.getObjects(); while (e.hasMoreElements()) { ASN1Set set = ASN1Set.getInstance(e.nextElement()); for (int i = 0; i < set.size(); i++) { ASN1Sequence s = ASN1Sequence.getInstance(set.getObjectAt(i)); if (s.size() != 2) { throw new IllegalArgumentException("badly sized pair"); } ordering.addElement(DERObjectIdentifier.getInstance(s.getObjectAt(0))); DEREncodable value = s.getObjectAt(1); if (value instanceof DERString) { values.addElement(((DERString) value).getString()); } else { values.addElement("#" + bytesToString(Hex.encode(value.getDERObject().getDEREncoded()))); } added.addElement((i != 0) ? TRUE : FALSE); // to allow earlier JDK compatibility } } }
public EncryptedContentInfo(ASN1Sequence seq) { contentType = (DERObjectIdentifier) seq.getObjectAt(0); contentEncryptionAlgorithm = AlgorithmIdentifier.getInstance(seq.getObjectAt(1)); if (seq.size() > 2) { encryptedContent = ASN1OctetString.getInstance((ASN1TaggedObject) seq.getObjectAt(2), false); } }
/** * EncryptedContentInfo ::= SEQUENCE { contentType ContentType, contentEncryptionAlgorithm * ContentEncryptionAlgorithmIdentifier, encryptedContent [0] IMPLICIT EncryptedContent OPTIONAL } * * <p>EncryptedContent ::= OCTET STRING */ public static EncContent fromASN1(ASN1Encodable content) { ASN1Sequence sequence = (ASN1Sequence) content; ASN1ObjectIdentifier contentType = (ASN1ObjectIdentifier) (sequence.getObjectAt(0)); int nid = ASN1Registry.obj2nid(contentType); EncContent ec = new EncContent(); ec.setContentType(nid); ec.setAlgorithm(AlgorithmIdentifier.getInstance(sequence.getObjectAt(1))); if (sequence.size() > 2 && sequence.getObjectAt(2) instanceof ASN1TaggedObject && ((ASN1TaggedObject) (sequence.getObjectAt(2))).getTagNo() == 0) { ASN1Encodable ee = ((ASN1TaggedObject) (sequence.getObjectAt(2))).getObject(); if (ee instanceof ASN1Sequence && ((ASN1Sequence) ee).size() > 0) { ByteList combinedOctets = new ByteList(); Enumeration enm = ((ASN1Sequence) ee).getObjects(); while (enm.hasMoreElements()) { byte[] octets = ((ASN1OctetString) enm.nextElement()).getOctets(); combinedOctets.append(octets); } ec.setEncData(new DEROctetString(combinedOctets.bytes())); } else { ec.setEncData((ASN1OctetString) ee); } } return ec; }
private SinglePubInfo(ASN1Sequence seq) { pubMethod = ASN1Integer.getInstance(seq.getObjectAt(0)); if (seq.size() == 2) { pubLocation = GeneralName.getInstance(seq.getObjectAt(1)); } }
public PaceInfo(ASN1Sequence seq) { protocol = (ASN1ObjectIdentifier) seq.getObjectAt(0); version = (ASN1Integer) seq.getObjectAt(1); if (seq.size() > 2) { parameterId = (ASN1Integer) seq.getObjectAt(2); } }
private static boolean withinDNSubtree(ASN1Sequence dns, ASN1Sequence subtree) { if (subtree.size() < 1) { return false; } if (subtree.size() > dns.size()) { return false; } for (int j = subtree.size() - 1; j >= 0; j--) { if (!subtree.getObjectAt(j).equals(dns.getObjectAt(j))) { return false; } } return true; }
/** * Returns the targets in this target information extension. * * @return Returns the targets. */ public Targets[] getTargetsObjects() { Targets[] copy = new Targets[targets.size()]; int count = 0; for (Enumeration e = targets.getObjects(); e.hasMoreElements(); ) { copy[count++] = Targets.getInstance(e.nextElement()); } return copy; }
@DSGenerator( tool_name = "Doppelganger", tool_version = "2.0", generated_on = "2013-12-30 13:00:22.496 -0500", hash_original_method = "6A7E42DF8EF9B09B844C872DFCA023C7", hash_generated_method = "21B5E94B1503EB3B81CAD22E6A3D29F8") public IssuerSerial(ASN1Sequence seq) { if (seq.size() != 2 && seq.size() != 3) { throw new IllegalArgumentException("Bad sequence size: " + seq.size()); } issuer = GeneralNames.getInstance(seq.getObjectAt(0)); serial = DERInteger.getInstance(seq.getObjectAt(1)); if (seq.size() == 3) { issuerUID = DERBitString.getInstance(seq.getObjectAt(2)); } }
private PKIStatusInfo(ASN1Sequence seq) { this.status = ASN1Integer.getInstance(seq.getObjectAt(0)); this.statusString = null; this.failInfo = null; if (seq.size() > 2) { this.statusString = PKIFreeText.getInstance(seq.getObjectAt(1)); this.failInfo = DERBitString.getInstance(seq.getObjectAt(2)); } else if (seq.size() > 1) { Object obj = seq.getObjectAt(1); if (obj instanceof DERBitString) { this.failInfo = DERBitString.getInstance(obj); } else { this.statusString = PKIFreeText.getInstance(obj); } } }
public CryptEngineImpl(Context ctx) throws Exception { // Получаем действующее хранилище IKeyStorage storage = KeyStorageFactory.getKeyStorage(ctx); Log.v("TFORWARD.CryptEngineImpl", "Decoding public key..."); byte[] publicKey = Base64.decode(storage.getKey(IKeyStorage.PUBLIC_KEY_TYPE), Base64.DEFAULT); Log.v("TFORWARD.CryptEngineImpl", "Decoding ASN1 Structure"); ASN1InputStream asnStream = new ASN1InputStream(publicKey); ASN1Sequence sequence = null; try { Log.v("TFORWARD.CryptEngineImpl", "Reading ASN1 Sequence"); sequence = (ASN1Sequence) asnStream.readObject(); } finally { asnStream.close(); } Log.v("TFORWARD.CryptEngineImpl", "Creating certificate. " + sequence.size()); Certificate certificate = Certificate.getInstance(sequence); SubjectPublicKeyInfo publicKeyInfo = certificate.getSubjectPublicKeyInfo(); RSAPublicKey publicKeyStructure = RSAPublicKey.getInstance(publicKeyInfo.parsePublicKey()); BigInteger mod = publicKeyStructure.getModulus(); BigInteger pubExp = publicKeyStructure.getPublicExponent(); publicRsaKey = new RSAKeyParameters(false, mod, pubExp); // ------------------------ PRIVATE KEY -------------------------------- byte[] privateKeyData = Base64.decode(storage.getKey(IKeyStorage.SECRET_KEY_TYPE), Base64.DEFAULT); asnStream = new ASN1InputStream(privateKeyData); ASN1Sequence asnSequence = null; try { asnSequence = (ASN1Sequence) asnStream.readObject(); } finally { asnStream.close(); } RSAPrivateKey privateKey = RSAPrivateKey.getInstance(asnSequence); privateRsaKey = new RSAPrivateCrtKeyParameters( privateKey.getModulus(), privateKey.getPublicExponent(), privateKey.getPrivateExponent(), privateKey.getPrime1(), privateKey.getPrime2(), privateKey.getExponent1(), privateKey.getExponent2(), privateKey.getCoefficient()); RSAEngine engine = new RSAEngine(); digest = new MD5Digest(); cipher = new PKCS1Encoding(engine); }
private PolicyConstraints(ASN1Sequence seq) { if (seq.size() > 2) { throw new IllegalArgumentException("sequence length > 2"); } for (int i = 0; i < seq.size(); i++) { ASN1TaggedObject taggedObj = ASN1TaggedObject.getInstance(seq.getObjectAt(i)); switch (taggedObj.getTagNo()) { case 0: requireExplicitPolicy = ASN1Integer.getInstance(taggedObj.getObject()).getValue().intValue(); break; case 1: inhibitPolicyMapping = ASN1Integer.getInstance(taggedObj.getObject()).getValue().intValue(); break; default: throw new IllegalArgumentException("wrong tag number"); } } }
public static LogotypeReference getInstance(ASN1Sequence seq) { ASN1Sequence refStructHashSeq = null; ASN1Sequence refStructURISeq = null; if (seq.size() != 2) { throw new IllegalArgumentException("size of sequence must be 2 not " + seq.size()); } refStructHashSeq = ASN1Sequence.getInstance(seq.getObjectAt(0)); refStructURISeq = ASN1Sequence.getInstance(seq.getObjectAt(1)); DigestInfo[] refStructHash = null; DERIA5String[] refStructURI = null; { Vector<DigestInfo> v = new Vector<DigestInfo>(); for (int i = 0; i < refStructHashSeq.size(); i++) { DigestInfo di = DigestInfo.getInstance(refStructHashSeq.getObjectAt(i)); v.add(di); } refStructHash = v.toArray(new DigestInfo[refStructHashSeq.size()]); } { Vector<DERIA5String> v = new Vector<DERIA5String>(); for (int i = 0; i < refStructURISeq.size(); i++) { DERIA5String di = DERIA5String.getInstance(refStructURISeq.getObjectAt(i)); v.add(di); } refStructHash = v.toArray(new DigestInfo[refStructURISeq.size()]); } return new LogotypeReference(refStructHash, refStructURI); }
public X9Curve(X9FieldID fieldID, ASN1Sequence seq) { if (fieldID.getIdentifier().equals(prime_field)) { BigInteger q = ((DERInteger) fieldID.getParameters()).getValue(); X9FieldElement x9A = new X9FieldElement(true, q, (ASN1OctetString) seq.getObjectAt(0)); X9FieldElement x9B = new X9FieldElement(true, q, (ASN1OctetString) seq.getObjectAt(1)); curve = new ECCurve.Fp(q, x9A.getValue().toBigInteger(), x9B.getValue().toBigInteger()); } else { throw new RuntimeException("not implemented"); } if (seq.size() == 3) { seed = ((DERBitString) seq.getObjectAt(2)).getBytes(); } }
private ECCCMSSharedInfo(ASN1Sequence seq) { this.keyInfo = AlgorithmIdentifier.getInstance(seq.getObjectAt(0)); if (seq.size() == 2) { this.entityUInfo = null; this.suppPubInfo = ASN1OctetString.getInstance((ASN1TaggedObject) seq.getObjectAt(1), true).getOctets(); } else { this.entityUInfo = ASN1OctetString.getInstance((ASN1TaggedObject) seq.getObjectAt(1), true).getOctets(); this.suppPubInfo = ASN1OctetString.getInstance((ASN1TaggedObject) seq.getObjectAt(2), true).getOctets(); } }
public SemanticsInformation(ASN1Sequence seq) { Enumeration e = seq.getObjects(); if (seq.size() < 1) { throw new IllegalArgumentException("no objects in SemanticsInformation"); } Object object = e.nextElement(); if (object instanceof DERObjectIdentifier) { semanticsIdentifier = DERObjectIdentifier.getInstance(object); if (e.hasMoreElements()) { object = e.nextElement(); } else { object = null; } } if (object != null) { ASN1Sequence generalNameSeq = ASN1Sequence.getInstance(object); nameRegistrationAuthorities = new GeneralName[generalNameSeq.size()]; for (int i = 0; i < generalNameSeq.size(); i++) { nameRegistrationAuthorities[i] = GeneralName.getInstance(generalNameSeq.getObjectAt(i)); } } }
private CRL readDERCRL(ASN1InputStream aIn) throws IOException, CRLException { ASN1Sequence seq = (ASN1Sequence) aIn.readObject(); if (seq.size() > 1 && seq.getObjectAt(0) instanceof ASN1ObjectIdentifier) { if (seq.getObjectAt(0).equals(PKCSObjectIdentifiers.signedData)) { sCrlData = SignedData.getInstance( ASN1Sequence.getInstance((ASN1TaggedObject) seq.getObjectAt(1), true)) .getCRLs(); return getCRL(); } } return createCRL(CertificateList.getInstance(seq)); }
/** * 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) { ASN1Sequence seq = attrCert.getAcinfo().getAttributes(); List list = new ArrayList(); for (int i = 0; i != seq.size(); i++) { Attribute attr = Attribute.getInstance(seq.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()]); }