use of edu.uiuc.ncsa.security.util.pkcs.MyPKCS10CertRequest in project OA4MP by ncsa.
the class CertAndKeyUtilTest method testCertReq.
@Test
public void testCertReq() throws Exception {
KeyPair keyPair = KeyUtil.generateKeyPair();
// Can't really do much to check. If it completes though we are in the ballpark.
System.out.println("Public key:\n" + KeyUtil.toX509PEM(keyPair.getPublic()));
System.out.println("Private key:\n" + KeyUtil.toPKCS8PEM(keyPair.getPrivate()));
MyPKCS10CertRequest cr = CertUtil.createCertRequest(keyPair);
System.out.println("Cert request:\n" + cr);
assert true;
}
use of edu.uiuc.ncsa.security.util.pkcs.MyPKCS10CertRequest in project OA4MP by ncsa.
the class InitServlet method verifyAndGet.
@Override
public ServiceTransaction verifyAndGet(IssuerResponse iResponse) throws IOException {
AGResponse agResponse = (AGResponse) iResponse;
Map<String, String> params = agResponse.getParameters();
ServiceTransaction transaction = newTransaction();
transaction.setAuthorizationGrant(agResponse.getGrant());
debug("creating transaction for trans id=" + transaction.getIdentifierString());
transaction.setAuthGrantValid(false);
transaction.setAccessTokenValid(false);
transaction.setCallback(URI.create(params.get(OAUTH_CALLBACK)));
MyPKCS10CertRequest certReq = null;
// Fix for CIL-409
if (!params.containsKey(CERT_REQUEST)) {
throw new GeneralException("Error: missing cert request parameter.");
}
String rawCR = params.get(CERT_REQUEST);
if (isEmpty(rawCR)) {
throw new GeneralException("Error: empty cert request.");
}
try {
certReq = CertUtil.fromStringToCertReq(rawCR);
} catch (Throwable throwable) {
throwable.printStackTrace();
throw new GeneralException("Error: cert request is bad/not understandable:" + (rawCR == null ? "(null)" : rawCR), throwable);
}
transaction.setCertReq(certReq);
// Assumption here is that the cert lifetime is in milliseconds
transaction.setLifetime(Long.parseLong(params.get(CERT_LIFETIME)));
return transaction;
}
use of edu.uiuc.ncsa.security.util.pkcs.MyPKCS10CertRequest in project OA4MP by ncsa.
the class OA2MPService method getCert.
public AssetResponse getCert(OA2Asset a, ATResponse2 atResponse2) {
KeyPair keyPair = getNextKeyPair();
MyPKCS10CertRequest certReq = null;
try {
certReq = CertUtil.createCertRequest(keyPair, a.getUsername());
} catch (Throwable e) {
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
}
throw new GeneralException("Could no create cert request", e);
}
a.setPrivateKey(keyPair.getPrivate());
a.setCertReq(certReq);
Map<String, String> m1 = getAssetParameters(a);
preGetCert(a, m1);
if (MANUAL_TEST) {
return manualTest(a, m1);
}
DelegatedAssetResponse daResp = getEnvironment().getDelegationService().getCert(atResponse2, getEnvironment().getClient(), m1);
AssetResponse par = new AssetResponse();
MyX509Certificates myX509Certificate = (MyX509Certificates) daResp.getProtectedAsset();
par.setX509Certificates(myX509Certificate.getX509Certificates());
postGetCert(a, par);
a.setCertificates(par.getX509Certificates());
getEnvironment().getAssetStore().save(a);
return par;
}
use of edu.uiuc.ncsa.security.util.pkcs.MyPKCS10CertRequest in project OA4MP by ncsa.
the class OA4MPService method preRequestCert.
@Override
public void preRequestCert(Asset asset, Map additionalParameters) {
KeyPair keyPair = getNextKeyPair();
MyPKCS10CertRequest certReq = null;
try {
certReq = CertUtil.createCertRequest(keyPair);
} catch (Throwable e) {
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
}
throw new GeneralException("Could not create cert request", e);
}
asset.setPrivateKey(keyPair.getPrivate());
asset.setCertReq(certReq);
additionalParameters.put(ClientEnvironment.CERT_REQUEST_KEY, Base64.encodeBase64String(asset.getCertReq().getEncoded()));
// additionalParameters.put(ClientEnvironment.CERT_REQUEST_KEY, "Mairzy doates and does eat stoats.");
if (!additionalParameters.containsKey(getEnvironment().getConstants().get(CALLBACK_URI_KEY))) {
additionalParameters.put(getEnvironment().getConstants().get(CALLBACK_URI_KEY), getEnvironment().getCallback().toString());
}
if (0 <= getEnvironment().getCertLifetime()) {
additionalParameters.put(ClientEnvironment.CERT_LIFETIME_KEY, getEnvironment().getCertLifetime());
}
}
use of edu.uiuc.ncsa.security.util.pkcs.MyPKCS10CertRequest in project OA4MP by ncsa.
the class MyProxyLogon method getCredentials.
/**
* Retrieves credentials from the MyProxy server.
*/
public void getCredentials() throws IOException, GeneralSecurityException {
KeyPairGenerator keyGenerator = KeyPairGenerator.getInstance(keyAlg);
keyGenerator.initialize(getKeySize());
this.keypair = keyGenerator.genKeyPair();
MyPKCS10CertRequest pkcs10 = CertUtil.createCertRequest(this.keypair, pkcs10SigAlgName, DN, pkcs10Provider);
getCredentials(pkcs10.getEncoded());
}
Aggregations