Skip to content
Snippets Groups Projects
Commit 035874ef authored by Felix Sidokhine's avatar Felix Sidokhine
Browse files

fixed minor NPE bug

parent e7974294
No related branches found
No related tags found
No related merge requests found
......@@ -20,7 +20,7 @@ public class DeviceDao extends AbstractDao<Device> {
String createTable = "CREATE TABLE devices (" +
"deviceId varchar(255), " +
"owner varchar(255)," +
"displayName varchar(10)," +
"displayName varchar(255)," +
"certificate varchar(5000), "+
"privatekey varchar(5000)," +
"PRIMARY KEY (deviceId))";
......
......@@ -19,8 +19,9 @@ import java.util.Date;
@Slf4j
public class UserBuilder {
public static User generateUser(User user){
public static User generateUser(User user) {
try {
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
keyPairGenerator.initialize(4096);
KeyPair keyPair = keyPairGenerator.generateKeyPair();
......@@ -33,10 +34,10 @@ public class UserBuilder {
SubjectPublicKeyInfo.getInstance(keyPair.getPublic().getEncoded())
);
user.setPrivateKey(keyPair.getPrivate());
user.setCertificate(CertificateSigner.signCertificate(JamsCA.CA.getPrivateKey(),builder, ExtensionLibrary.userExtensions));
user.setCertificate(CertificateSigner.signCertificate(JamsCA.CA.getPrivateKey(), builder, ExtensionLibrary.userExtensions));
return user;
}
catch (Exception e){
} catch (Exception e) {
log.error("Could not generate a user certificate: " + e.toString());
return null;
}
......
......@@ -37,7 +37,8 @@ public class Device extends X509Entity implements DatabaseObject {
ps.setString(2, owner);
ps.setString(3,displayName);
ps.setString(4, X509Utils.getPEMStringFromCertificate(this.getCertificate()));
ps.setString(5, X509Utils.getPEMStringFromPrivateKey(this.getPrivateKey()));
//Devices do not have private keys exposed.
ps.setString(5, "");
return ps;
}
......
......@@ -22,6 +22,8 @@ public class DeviceRegistrationResponse {
for(int i=0;i<certificateChain.length;i++){
stringBuilder.append(X509Utils.getPEMStringFromCertificate(certificateChain[i])).append("\n");
}
//remove the last \n because it's useless.
stringBuilder.deleteCharAt(stringBuilder.length()-1);
this.certificateChain = stringBuilder.toString();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment