Search in sources :

Example 11 with MyPKCS10CertRequest

use of edu.uiuc.ncsa.security.util.pkcs.MyPKCS10CertRequest in project OA4MP by ncsa.

the class AssetStoreTest method testUpdate.

public void testUpdate(AssetStore store) throws Exception {
    if (store == null) {
        System.out.println("WARNING: no asset store configured, skipping test.");
        return;
    }
    SecureRandom secureRandom = new SecureRandom();
    String r1 = Long.toHexString(secureRandom.nextLong());
    KeyPair kp1 = KeyUtil.generateKeyPair();
    PrivateKey privateKey1 = kp1.getPrivate();
    MyPKCS10CertRequest cr1 = CertUtil.createCertRequest(kp1);
    String rawCR1 = CertUtil.fromCertReqToString(cr1);
    String username1 = "testUser-" + r1;
    URI redirect1 = URI.create("http://test.foo/test/" + r1 + "/" + System.currentTimeMillis());
    Identifier token1 = BasicIdentifier.newID("token:id:/" + r1 + "/" + System.currentTimeMillis());
    Identifier id1 = BasicIdentifier.newID("asset:id:/" + r1 + "/" + System.currentTimeMillis());
    Asset asset = store.create();
    assert asset != null : "Error: The store is not producing valid assets when requested. A null was returned";
    asset.setIdentifier(id1);
    asset.setUsername(username1);
    asset.setPrivateKey(privateKey1);
    asset.setRedirect(redirect1);
    asset.setToken(token1);
    asset.setCertReq(cr1);
    store.save(asset);
    // Now try and update the identifier -- that should fail.
    String r2 = Long.toHexString(secureRandom.nextLong());
    Identifier id2 = BasicIdentifier.newID("asset:id:/" + r2 + "/" + System.currentTimeMillis());
    asset.setIdentifier(id2);
    // identifier means the object needs to be registered first.
    try {
        store.update(asset);
        assert false : "Error: was able to update the identifier.";
    } catch (UnregisteredObjectException t) {
        assert true;
    }
    // ok, set the id back since that worked.
    asset.setIdentifier(id1);
    // now for everything else.
    KeyPair kp2 = KeyUtil.generateKeyPair();
    PrivateKey privateKey2 = kp2.getPrivate();
    MyPKCS10CertRequest cr2 = CertUtil.createCertRequest(kp2);
    String rawCR2 = CertUtil.fromCertReqToString(cr2);
    String username2 = "testUser-" + r2;
    URI redirect2 = URI.create("http://test.foo/test/" + r2 + "/" + System.currentTimeMillis());
    Identifier token2 = BasicIdentifier.newID("token:id:/" + r1 + "/" + System.currentTimeMillis());
    asset.setUsername(username2);
    asset.setPrivateKey(privateKey2);
    asset.setCertReq(cr2);
    asset.setRedirect(redirect2);
    asset.setToken(token2);
    store.update(asset);
    Asset asset2 = store.get(asset.getIdentifier());
    assert asset2.getUsername().equals(username2);
    assert asset2.getPrivateKey().equals(privateKey2);
    assert CertUtil.fromCertReqToString(asset2.getCertReq()).equals(rawCR2);
    assert asset2.getToken().equals(token2);
    assert asset2.getRedirect().equals(redirect2);
    store.remove(asset.getIdentifier());
}
Also used : KeyPair(java.security.KeyPair) PrivateKey(java.security.PrivateKey) BasicIdentifier(edu.uiuc.ncsa.security.core.util.BasicIdentifier) Identifier(edu.uiuc.ncsa.security.core.Identifier) UnregisteredObjectException(edu.uiuc.ncsa.security.core.exceptions.UnregisteredObjectException) SecureRandom(java.security.SecureRandom) Asset(edu.uiuc.ncsa.myproxy.oa4mp.client.Asset) URI(java.net.URI) MyPKCS10CertRequest(edu.uiuc.ncsa.security.util.pkcs.MyPKCS10CertRequest)

Example 12 with MyPKCS10CertRequest

use of edu.uiuc.ncsa.security.util.pkcs.MyPKCS10CertRequest in project OA4MP by ncsa.

the class PKCS10_CSR_Test method testSubjects.

@Test
public void testSubjects() throws Exception {
    MyPKCS10CertRequest certReq = CertUtil.fromStringToCertReq(GOOD_GLOBUS_CR);
    assert certReq.getPublicKey() != null;
    certReq = CertUtil.fromStringToCertReq(TEST_WITH_SUBJECT);
    assert certReq.getPublicKey() != null;
    certReq = CertUtil.fromStringToCertReq(TEST_NO_SUBJECT);
    assert certReq.getPublicKey() != null;
}
Also used : MyPKCS10CertRequest(edu.uiuc.ncsa.security.util.pkcs.MyPKCS10CertRequest) Test(org.junit.Test)

Example 13 with MyPKCS10CertRequest

use of edu.uiuc.ncsa.security.util.pkcs.MyPKCS10CertRequest in project OA4MP by ncsa.

the class OA2AssetConverter method fromMap.

@Override
public Asset fromMap(ConversionMap<String, Object> map, Asset asset) {
    OA2Asset a = (OA2Asset) super.fromMap(map, asset);
    String rawCR = map.getString(getASK().certReq());
    if (rawCR != null) {
        MyPKCS10CertRequest certReq = CertUtil.fromStringToCertReq(rawCR);
        a.setCertReq(certReq);
    }
    String at = map.getString(getASK().accessToken());
    if (at != null)
        a.setAccessToken(new AccessTokenImpl(URI.create(at)));
    String rt = map.getString(getASK().refreshToken());
    if (rt != null) {
        RefreshToken refreshToken = new OA2RefreshTokenImpl(URI.create(rt));
        refreshToken.setExpiresIn(map.getLong(getASK().refreshLifetime()));
        a.setRefreshToken(refreshToken);
    }
    String state = map.getString(getASK().state());
    if (state != null) {
        a.setState(state);
    }
    a.setNonce(map.getString(getASK().nonce()));
    if (map.containsKey(OA2Claims.ISSUED_AT)) {
        a.setIssuedAt(map.getDate(OA2Claims.ISSUED_AT));
    }
    return a;
}
Also used : RefreshToken(edu.uiuc.ncsa.security.delegation.token.RefreshToken) AccessTokenImpl(edu.uiuc.ncsa.security.delegation.token.impl.AccessTokenImpl) MyPKCS10CertRequest(edu.uiuc.ncsa.security.util.pkcs.MyPKCS10CertRequest) OA2RefreshTokenImpl(edu.uiuc.ncsa.security.oauth_2_0.OA2RefreshTokenImpl)

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