Constructors Summary |
---|
public NetscapeCertRequest(byte[] req)
this(getReq(req));
|
public NetscapeCertRequest(org.bouncycastle.asn1.ASN1Sequence spkac)
try
{
//
// SignedPublicKeyAndChallenge ::= SEQUENCE {
// publicKeyAndChallenge PublicKeyAndChallenge,
// signatureAlgorithm AlgorithmIdentifier,
// signature BIT STRING
// }
//
if (spkac.size() != 3)
{
throw new IllegalArgumentException("invalid SPKAC (size):"
+ spkac.size());
}
sigAlg = new AlgorithmIdentifier((ASN1Sequence)spkac
.getObjectAt(1));
sigBits = ((DERBitString)spkac.getObjectAt(2)).getBytes();
//
// PublicKeyAndChallenge ::= SEQUENCE {
// spki SubjectPublicKeyInfo,
// challenge IA5STRING
// }
//
ASN1Sequence pkac = (ASN1Sequence)spkac.getObjectAt(0);
if (pkac.size() != 2)
{
throw new IllegalArgumentException("invalid PKAC (len): "
+ pkac.size());
}
challenge = ((DERIA5String)pkac.getObjectAt(1)).getString();
//this could be dangerous, as ASN.1 decoding/encoding
//could potentially alter the bytes
content = new DERBitString(pkac);
SubjectPublicKeyInfo pubkeyinfo = new SubjectPublicKeyInfo(
(ASN1Sequence)pkac.getObjectAt(0));
X509EncodedKeySpec xspec = new X509EncodedKeySpec(new DERBitString(
pubkeyinfo).getBytes());
keyAlg = pubkeyinfo.getAlgorithmId();
pubkey = KeyFactory.getInstance(keyAlg.getObjectId().getId(), "BC")
.generatePublic(xspec);
}
catch (Exception e)
{
throw new IllegalArgumentException(e.toString());
}
|
public NetscapeCertRequest(String challenge, org.bouncycastle.asn1.x509.AlgorithmIdentifier signing_alg, PublicKey pub_key)
this.challenge = challenge;
sigAlg = signing_alg;
pubkey = pub_key;
ASN1EncodableVector content_der = new ASN1EncodableVector();
content_der.add(getKeySpec());
//content_der.add(new SubjectPublicKeyInfo(sigAlg, new RSAPublicKeyStructure(pubkey.getModulus(), pubkey.getPublicExponent()).getDERObject()));
content_der.add(new DERIA5String(challenge));
content = new DERBitString(new DERSequence(content_der));
|
Methods Summary |
---|
public java.lang.String | getChallenge()
return challenge;
|
public org.bouncycastle.asn1.x509.AlgorithmIdentifier | getKeyAlgorithm()
return keyAlg;
|
private org.bouncycastle.asn1.DERObject | getKeySpec()
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DERObject obj = null;
try
{
baos.write(pubkey.getEncoded());
baos.close();
ASN1InputStream derin = new ASN1InputStream(
new ByteArrayInputStream(baos.toByteArray()));
obj = derin.readObject();
}
catch (IOException ioe)
{
throw new InvalidKeySpecException(ioe.getMessage());
}
return obj;
|
public java.security.PublicKey | getPublicKey()
return pubkey;
|
private static org.bouncycastle.asn1.ASN1Sequence | getReq(byte[] r)
ASN1InputStream aIn = new ASN1InputStream(new ByteArrayInputStream(r));
return ASN1Sequence.getInstance(aIn.readObject());
|
public org.bouncycastle.asn1.x509.AlgorithmIdentifier | getSigningAlgorithm()
return sigAlg;
|
public void | setChallenge(java.lang.String value)
challenge = value;
|
public void | setKeyAlgorithm(org.bouncycastle.asn1.x509.AlgorithmIdentifier value)
keyAlg = value;
|
public void | setPublicKey(java.security.PublicKey value)
pubkey = value;
|
public void | setSigningAlgorithm(org.bouncycastle.asn1.x509.AlgorithmIdentifier value)
sigAlg = value;
|
public void | sign(java.security.PrivateKey priv_key)
sign(priv_key, null);
|
public void | sign(java.security.PrivateKey priv_key, java.security.SecureRandom rand)
Signature sig = Signature.getInstance(sigAlg.getObjectId().getId(),
"BC");
if (rand != null)
{
sig.initSign(priv_key, rand);
}
else
{
sig.initSign(priv_key);
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DEROutputStream deros = new DEROutputStream(baos);
ASN1EncodableVector pkac = new ASN1EncodableVector();
pkac.add(getKeySpec());
pkac.add(new DERIA5String(challenge));
try
{
deros.writeObject(new DERSequence(pkac));
deros.close();
}
catch (IOException ioe)
{
throw new SignatureException(ioe.getMessage());
}
sig.update(baos.toByteArray());
sigBits = sig.sign();
|
public org.bouncycastle.asn1.DERObject | toASN1Object()
ASN1EncodableVector spkac = new ASN1EncodableVector();
ASN1EncodableVector pkac = new ASN1EncodableVector();
try
{
pkac.add(getKeySpec());
}
catch (Exception e)
{
//ignore
}
pkac.add(new DERIA5String(challenge));
spkac.add(new DERSequence(pkac));
spkac.add(sigAlg);
spkac.add(new DERBitString(sigBits));
return new DERSequence(spkac);
|
public boolean | verify(java.lang.String challenge)
if (!challenge.equals(this.challenge))
{
return false;
}
//
// Verify the signature .. shows the response was generated
// by someone who knew the associated private key
//
Signature sig = Signature.getInstance(sigAlg.getObjectId().getId(),
"BC");
sig.initVerify(pubkey);
sig.update(content.getBytes());
return sig.verify(sigBits);
|