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());
}
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;
}
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;
}
Aggregations