Search in sources :

Example 6 with MyPKCS10CertRequest

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;
}
Also used : KeyPair(java.security.KeyPair) MyPKCS10CertRequest(edu.uiuc.ncsa.security.util.pkcs.MyPKCS10CertRequest) Test(org.junit.Test)

Example 7 with MyPKCS10CertRequest

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;
}
Also used : GeneralException(edu.uiuc.ncsa.security.core.exceptions.GeneralException) ServiceTransaction(edu.uiuc.ncsa.security.delegation.server.ServiceTransaction) AGResponse(edu.uiuc.ncsa.security.delegation.server.request.AGResponse) MyPKCS10CertRequest(edu.uiuc.ncsa.security.util.pkcs.MyPKCS10CertRequest)

Example 8 with MyPKCS10CertRequest

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;
}
Also used : KeyPair(java.security.KeyPair) GeneralException(edu.uiuc.ncsa.security.core.exceptions.GeneralException) AssetResponse(edu.uiuc.ncsa.myproxy.oa4mp.client.AssetResponse) MyX509Certificates(edu.uiuc.ncsa.security.delegation.token.MyX509Certificates) MyPKCS10CertRequest(edu.uiuc.ncsa.security.util.pkcs.MyPKCS10CertRequest)

Example 9 with MyPKCS10CertRequest

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());
    }
}
Also used : KeyPair(java.security.KeyPair) GeneralException(edu.uiuc.ncsa.security.core.exceptions.GeneralException) MyPKCS10CertRequest(edu.uiuc.ncsa.security.util.pkcs.MyPKCS10CertRequest)

Example 10 with MyPKCS10CertRequest

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());
}
Also used : KeyPairGenerator(java.security.KeyPairGenerator) MyPKCS10CertRequest(edu.uiuc.ncsa.security.util.pkcs.MyPKCS10CertRequest)

Aggregations

MyPKCS10CertRequest (edu.uiuc.ncsa.security.util.pkcs.MyPKCS10CertRequest)13 KeyPair (java.security.KeyPair)7 GeneralException (edu.uiuc.ncsa.security.core.exceptions.GeneralException)5 Test (org.junit.Test)3 Asset (edu.uiuc.ncsa.myproxy.oa4mp.client.Asset)2 Identifier (edu.uiuc.ncsa.security.core.Identifier)2 BasicIdentifier (edu.uiuc.ncsa.security.core.util.BasicIdentifier)2 ServiceTransaction (edu.uiuc.ncsa.security.delegation.server.ServiceTransaction)2 MyX509Certificates (edu.uiuc.ncsa.security.delegation.token.MyX509Certificates)2 URI (java.net.URI)2 PrivateKey (java.security.PrivateKey)2 SecureRandom (java.security.SecureRandom)2 AssetResponse (edu.uiuc.ncsa.myproxy.oa4mp.client.AssetResponse)1 ConnectionException (edu.uiuc.ncsa.security.core.exceptions.ConnectionException)1 InvalidCertRequestException (edu.uiuc.ncsa.security.core.exceptions.InvalidCertRequestException)1 NFWException (edu.uiuc.ncsa.security.core.exceptions.NFWException)1 UnregisteredObjectException (edu.uiuc.ncsa.security.core.exceptions.UnregisteredObjectException)1 AGResponse (edu.uiuc.ncsa.security.delegation.server.request.AGResponse)1 PARequest (edu.uiuc.ncsa.security.delegation.server.request.PARequest)1 PAResponse (edu.uiuc.ncsa.security.delegation.server.request.PAResponse)1