1 package org.bouncycastle.asn1.mozilla; 2 3 import org.bouncycastle.asn1.ASN1Encodable; 4 import org.bouncycastle.asn1.DERObject; 5 import org.bouncycastle.asn1.DERIA5String; 6 import org.bouncycastle.asn1.ASN1Sequence; 7 import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo; 8 9 /** 10 * This is designed to parse 11 * the PublicKeyAndChallenge created by the KEYGEN tag included by 12 * Mozilla based browsers. 13 * <pre> 14 * PublicKeyAndChallenge ::= SEQUENCE { 15 * spki SubjectPublicKeyInfo, 16 * challenge IA5STRING 17 * } 18 * 19 * </pre> 20 */ 21 public class PublicKeyAndChallenge 22 extends ASN1Encodable 23 { 24 private ASN1Sequence pkacSeq; 25 private SubjectPublicKeyInfo spki; 26 private DERIA5String challenge; 27 28 public static PublicKeyAndChallenge getInstance(Object obj) 29 { 30 if (obj instanceof PublicKeyAndChallenge) 31 { 32 return (PublicKeyAndChallenge)obj; 33 } 34 else if (obj instanceof ASN1Sequence) 35 { 36 return new PublicKeyAndChallenge((ASN1Sequence)obj); 37 } 38 39 throw new IllegalArgumentException("unkown object in factory"); 40 } 41 42 public PublicKeyAndChallenge(ASN1Sequence seq) 43 { 44 pkacSeq = seq; 45 spki = SubjectPublicKeyInfo.getInstance(seq.getObjectAt(0)); 46 challenge = DERIA5String.getInstance(seq.getObjectAt(1)); 47 } 48 49 public DERObject toASN1Object() 50 { 51 return pkacSeq; 52 } 53 54 public SubjectPublicKeyInfo getSubjectPublicKeyInfo() 55 { 56 return spki; 57 } 58 59 public DERIA5String getChallenge() 60 { 61 return challenge; 62 } 63 } 64