use of org.mozilla.jss.asn1.SET in project OpenAM by OpenRock.
the class SecureLogHelperJSSImpl method createBagAttrs.
/**
* Creates bag attributes.
* @param nickName The nickname of the key / signature
* @param localKeyId A hash of the entry to uniquely identify the given
* key / signature
* @throws Exception if it fails to generate key identifier
*/
private SET createBagAttrs(String nickName, byte[] localKeyId) throws Exception {
try {
SET attrs = new SET();
SEQUENCE nickNameAttr = new SEQUENCE();
nickNameAttr.addElement(SafeBag.FRIENDLY_NAME);
SET nickNameSet = new SET();
nickNameSet.addElement(new BMPString(nickName));
nickNameAttr.addElement(nickNameSet);
attrs.addElement(nickNameAttr);
SEQUENCE localKeyAttr = new SEQUENCE();
localKeyAttr.addElement(SafeBag.LOCAL_KEY_ID);
SET localKeySet = new SET();
localKeySet.addElement(new OCTET_STRING(localKeyId));
localKeyAttr.addElement(localKeySet);
attrs.addElement(localKeyAttr);
return attrs;
} catch (Exception e) {
Debug.error("SecureLogHelper.createBagAttrs() : " + " Exception : ", e);
throw new Exception("Failed to create Key Bag - " + e.toString());
}
}
use of org.mozilla.jss.asn1.SET in project OpenAM by OpenRock.
the class SecureLogHelperJSSImpl method AddToSecretStore.
/**
* Adds secret information to the secret Storage.
* @param cryptoMaterial : The data to be added
*/
private SEQUENCE AddToSecretStore(byte[] cryptoMaterial, String DataType) throws Exception {
SEQUENCE encSafeContents = new SEQUENCE();
ASN1Value data = new OCTET_STRING(cryptoMaterial);
byte[] localKeyId = createLocalKeyId(cryptoMaterial);
SET keyAttrs = createBagAttrs(DataType, localKeyId);
// attributes: user friendly name, Local Key ID
SafeBag keyBag = new SafeBag(SafeBag.SECRET_BAG, data, keyAttrs);
encSafeContents.addElement(keyBag);
return encSafeContents;
}
use of org.mozilla.jss.asn1.SET in project OpenAM by OpenRock.
the class SecureLogHelperJSSImpl method readFromSecretStore.
/**
* Returns matched secret data from from the secret Storage.
* At a time there are only 3 things in logger's secure store file
* - initialkey, currentkey and current signature
* In the verifier secure store file there is just the initial key of the
* logger and the currentKey
* @param filename file for secret storage
* @param dataType The kind of data to be read, whether it is a
* signature or a key
* @param password password for the file
* @return secure data that is matched with dataType
* @throws Exception if it fails to read secret data from secret store
*/
byte[] readFromSecretStore(String filename, String dataType, AMPassword password) throws Exception {
// open input file for reading
FileInputStream infile = null;
infile = new FileInputStream(filename);
// Decode the P12 file
PFX.Template pfxt = new PFX.Template();
PFX pfx = (PFX) pfxt.decode(new BufferedInputStream(infile, 2048));
// Verify the MAC on the PFX. This is important to be sure
// it hasn't been tampered with.
StringBuffer reason = new StringBuffer();
MessageDigest md = MessageDigest.getInstance("SHA");
Password jssPasswd = new Password(new String(md.digest(password.getByteCopy()), "UTF-8").toCharArray());
md.reset();
if (!pfx.verifyAuthSafes(jssPasswd, reason)) {
throw new Exception("AuthSafes failed to verify because: " + reason.toString());
}
AuthenticatedSafes authSafes = pfx.getAuthSafes();
SEQUENCE safeContentsSequence = authSafes.getSequence();
byte[] cryptoData = null;
// Loop over contents of the authenticated safes
for (int i = 0; i < safeContentsSequence.size(); i++) {
// The safeContents may or may not be encrypted. We always send
// the password in. It will get used if it is needed. If the
// decryption of the safeContents fails for some reason (like
// a bad password), then this method will throw an exception
SEQUENCE safeContents = authSafes.getSafeContentsAt(jssPasswd, i);
SafeBag safeBag = null;
ASN1Value val = null;
// Go through all the bags in this SafeContents
for (int j = 0; j < safeContents.size(); j++) {
safeBag = (SafeBag) safeContents.elementAt(j);
// look for bag attributes and then choose the key
SET attribs = safeBag.getBagAttributes();
if (attribs == null) {
Debug.error("Bag has no attributes");
} else {
for (int b = 0; b < attribs.size(); b++) {
Attribute a = (Attribute) attribs.elementAt(b);
if (a.getType().equals(SafeBag.FRIENDLY_NAME)) {
// the friendly name attribute is a nickname
BMPString bs = (BMPString) ((ANY) a.getValues().elementAt(0)).decodeWith(BMPString.getTemplate());
if (dataType.equals(bs.toString())) {
// look at the contents of the bag
val = safeBag.getInterpretedBagContent();
break;
}
}
}
}
}
if (val instanceof ANY)
cryptoData = ((ANY) val).getContents();
}
// Close the file
infile.close();
return cryptoData;
}
use of org.mozilla.jss.asn1.SET in project AlgorithmsSolutions by Allenskoo856.
the class FileIndex method main.
public static void main(String[] args) {
ST<String, SET<File>> st = new ST<String, SET<File>>();
for (String filename : args) {
File file = new File(filename);
In in = new In(file);
while (!in.isEmpty()) {
String word = in.readString();
if (!st.contains(word)) {
st.put(word, new SET<File>());
}
SET<File> set = st.get(word);
set.add(file);
}
}
while (!StdIn.isEmpty()) {
String query = StdIn.readString();
if (st.contains(query)) {
for (File file : st.get(query)) {
StdOut.println(" " + file.getName());
}
}
}
}
use of org.mozilla.jss.asn1.SET in project AlgorithmsSolutions by Allenskoo856.
the class WhiteFilter method main.
public static void main(String[] args) {
SET<String> set = new SET<String>();
In in = new In(args[0]);
while (!in.isEmpty()) {
set.add(in.readString());
}
while (!StdIn.isEmpty()) {
String word = StdIn.readString();
if (set.contains(word)) {
StdOut.print(word + " ");
}
}
}
Aggregations