私はJBOSS上で実行されているWebサービスを持っています。そのWebサービスにはpublic X509Certificate provideCertificate(String name, PublicKey key){ ... }
というメソッドがあり、クライアントに新しい証明書を提供し、他の当事者と通信します。WebサービスからX509Certificateを返す
問題は、PublicKeyを受け取ることができません。なぜなら、JAXBはそのインターフェイスに不満を持ち、空のコンストラクタを持っていないので、X509Certificateを返すことができないからです(JBOSSは言う)。
私はこれらのオブジェクトをある種のDTOオブジェクトにカプセル化しようとしましたが、うまく機能しませんでした。 これは、これを行う方法ではないかもしれないことを知っています。そのため、被験者のライトが大きく訴えられます。
自分のWebサービスコードは:
@javax.jws.WebService
public class CAWebService
{
@javax.jws.WebMethod
public X509Certificate addOperatorPublicKey(PublicKeyReqResDTO req)
{
PublicKey key = req.getPublicKey();
String operador = req.getNome();
X509CertImpl cert = null;
try
{
// used algorithm
String algorithm = "MD5WithRSA";
// create certificate for this request
PrivateKey privateKey = caKeyPair.getPrivate();
X509CertInfo info = new X509CertInfo();
// 3600000 = 1 hour maximum duration
Date from = new Date();
Date to = new Date(from.getTime() + 3600000L);
CertificateValidity interval = new CertificateValidity(from, to);
BigInteger sn = new BigInteger(64, new SecureRandom());
X500Name owner = new X500Name(operador);
info.set(X509CertInfo.VALIDITY, interval);
info.set(X509CertInfo.SERIAL_NUMBER, new CertificateSerialNumber(sn));
info.set(X509CertInfo.SUBJECT, new CertificateSubjectName(owner));
info.set(X509CertInfo.ISSUER, new CertificateIssuerName(new X500Name("CA")));
info.set(X509CertInfo.KEY, new CertificateX509Key(key));
info.set(X509CertInfo.VERSION, new CertificateVersion(CertificateVersion.V3));
AlgorithmId algo = new AlgorithmId(AlgorithmId.md5WithRSAEncryption_oid);
info.set(X509CertInfo.ALGORITHM_ID, new CertificateAlgorithmId(algo));
// signs the certificate using this web service private key
cert = new X509CertImpl(info);
cert.sign(privateKey, algorithm);
// updates and re-signs
algo = (AlgorithmId)cert.get(X509CertImpl.SIG_ALG);
info.set(CertificateAlgorithmId.NAME + "." + CertificateAlgorithmId.ALGORITHM, algo);
cert = new X509CertImpl(info);
cert.sign(privateKey, algorithm);
}
//catch all the exceptions, its like 10 diffente ones
catch(....)
{
}
//is the name already on the valid cert list?
boolean found = false; int index = 0;
for(int i = 0; i < validList.size(); i++)
{
if(validList.get(i).getSubjectX500Principal().getName().equals(operador))
{
found = true; index = i;
break;
}
}
//the cert was already on the valid list, so we put it on the black list
if(found)
{
blackList.add(validList.get(index));
validList.remove(index);
validList.add(cert);
}
else
{
//didnt find so no need to put on the black list
validList.add(cert);
}
return cert;
}
もあるため、いくつかの理由X509CRL doesntのために黒と有効な証明書のリストを制御するためのArrayListを使用してイム.add()メソッドを含める..持続性に興味を持って もイムありません私はちょうどそれがウェブサービスがオンラインである間に働くことを望む、時間はオフラインになるeveything siezesが存在するかどうか気にしない。
ありがとうございます。
おかげで多くは、魔法のように動作します! – sap