use of net.cryptonomica.returns.BooleanWrapperObject in project cryptonomica by Cryptonomica.
the class OnlineVerificationAPI method approve.
// end of acceptTerms();
// /* --- Approve online verification (for Cryptonomica Complience Officer) */
@ApiMethod(name = "approve", path = "approve", httpMethod = ApiMethod.HttpMethod.POST)
@SuppressWarnings("unused")
public BooleanWrapperObject approve(// final HttpServletRequest httpServletRequest,
final User googleUser, @Named("onlineVerificationApproved") final Boolean onlineVerificationApproved, @Named("verificationNotes") final String verificationNotes, @Named("fingerprint") final String fingerprint) throws // see: https://cloud.google.com/appengine/docs/java/endpoints/exceptions
UnauthorizedException, BadRequestException, NotFoundException, NumberParseException, IllegalArgumentException {
/* --- Check authorization : CRYPTONOMICA OFFICER ONLY !!! */
CryptonomicaUser cryptonomicaUser = UserTools.ensureCryptonomicaOfficer(googleUser);
/* --- Check input: */
if (fingerprint == null || fingerprint.equals("") || fingerprint.length() != 40) {
throw new BadRequestException("fingerprint is missing or invalid");
}
if (onlineVerificationApproved == null) {
throw new IllegalArgumentException("onlineVerificationApproved is null");
} else if (onlineVerificationApproved == false) {
throw new BadRequestException("onlineVerificationApproved (checkbox): false");
}
// Check if OnlineVerification entity exists:
OnlineVerification onlineVerification = ofy().load().key(Key.create(OnlineVerification.class, fingerprint)).now();
if (onlineVerification == null) {
throw new NotFoundException("OnlineVeriication entity for fingerprint " + fingerprint + " does not exist in data base");
} else if (onlineVerification.getOnlineVerificationDataVerified() != null && onlineVerification.getOnlineVerificationDataVerified()) {
throw new BadRequestException("OnlineVerification already approved");
}
// mark Online Verification as approved:
// <<<<<< !!!
onlineVerification.setOnlineVerificationDataVerified(onlineVerificationApproved);
onlineVerification.setVerifiedById(googleUser.getUserId());
onlineVerification.setVerifiedByFirstNameLastName(cryptonomicaUser.getFirstName() + " " + cryptonomicaUser.getLastName());
onlineVerification.setVerifiedOn(new Date());
onlineVerification.setVerificationNotes(verificationNotes);
// mark key as verified:
PGPPublicKeyData pgpPublicKeyData = ofy().load().type(PGPPublicKeyData.class).filter("fingerprintStr", fingerprint).first().now();
if (pgpPublicKeyData == null) {
throw new NotFoundException("Key with fingerprint " + fingerprint + " not found");
}
//
pgpPublicKeyData.setOnlineVerificationFinished(Boolean.TRUE);
pgpPublicKeyData.setNationality(onlineVerification.getNationality().toUpperCase());
// save data to data store:
ofy().save().entity(onlineVerification).now();
ofy().save().entity(pgpPublicKeyData).now();
// Send email to user:
final Queue queue = QueueFactory.getDefaultQueue();
queue.add(TaskOptions.Builder.withUrl("/_ah/SendGridServlet").param("email", onlineVerification.getUserEmail().getEmail()).param("emailCC", "verification@cryptonomica.net").param("messageSubject", "[cryptonomica] Online verification for key: " + onlineVerification.getKeyID() + " approved").param("messageText", "Congratulation! \n\n" + onlineVerification.getFirstName().toUpperCase() + " " + onlineVerification.getLastName().toUpperCase() + ",\n\n" + "your request for online verification for key with fingerprint : " + fingerprint + " approved! \n\n" + "See verification information on:\n" + "https://cryptonomica.net/#/onlineVerificationView/" + fingerprint + "\n" + "(information is not public, you have to login with your google account " + onlineVerification.getUserEmail().getEmail() + ")\n\n" + "Best regards, \n\n" + "Cryptonomica team\n\n" + new Date().toString() + "\n\n" + "if you think it's wrong or it is an error, " + "please write to support@cryptonomica.net\n\n"));
// create result object:
BooleanWrapperObject result = new BooleanWrapperObject(onlineVerificationApproved, "Online Verification for key " + fingerprint + " approved");
return result;
}
use of net.cryptonomica.returns.BooleanWrapperObject in project cryptonomica by Cryptonomica.
the class EthNodeAPI method verifyEthAddress.
@ApiMethod(name = "verifyEthAddress", path = "verifyEthAddress", httpMethod = ApiMethod.HttpMethod.POST)
@SuppressWarnings("unused")
public BooleanWrapperObject verifyEthAddress(// final HttpServletRequest httpServletRequest,
final User googleUser, @Named("ethereumAcc") final String ethereumAcc) throws IllegalArgumentException, UnauthorizedException, Exception {
BooleanWrapperObject result = new BooleanWrapperObject();
// ensure registered user ( - may be later only for verified):
CryptonomicaUser cryptonomicaUser = UserTools.ensureCryptonomicaRegisteredUser(googleUser);
// check form:
LOG.warning("ethereumAcc" + ethereumAcc);
if (ethereumAcc == null || ethereumAcc.equals("")) {
throw new IllegalArgumentException("Provided text is to short or empty");
}
String tomcatWeb3jAPIkey = ofy().load().key(Key.create(AppSettings.class, "tomcatweb3jAPIkey")).now().getValue();
String urlHost = "https://tomcatweb3j.cryptonomica.net";
String urlPath = "/GetVerificationRequestDataServlet";
String urlAddress = urlHost + urlPath;
// HashMap<String, String> queryMap = new HashMap<>();
// queryMap.put("address", ethereumAcc);
String postRequestBody = "address=" + ethereumAcc;
HTTPResponse httpResponse = HttpService.postRequestWithAPIkey(urlAddress, postRequestBody, tomcatWeb3jAPIkey);
byte[] httpResponseContentBytes = httpResponse.getContent();
String httpResponseContentString = new String(httpResponseContentBytes, StandardCharsets.UTF_8);
// Test:
// Object resObj = new Gson().fromJson(httpResponseContentString, Object.class); // --- exception
// LOG.warning("resObj: " + new Gson().toJson(resObj));
LOG.warning("httpResponseContentString: " + httpResponseContentString);
VerificationRequestDataFromSC verificationRequestDataFromSC = GSON.fromJson(httpResponseContentString, VerificationRequestDataFromSC.class);
// GET Key from DataBase by fingerprint:
String unverifiedFingerprint = verificationRequestDataFromSC.getUnverifiedFingerprint();
String signedString = verificationRequestDataFromSC.getSignedString();
PGPPublicKeyData pgpPublicKeyData = PGPTools.getPGPPublicKeyDataFromDataBaseByFingerprint(unverifiedFingerprint);
Boolean keyVerifiedOffline = pgpPublicKeyData.getVerified();
Boolean keyVerifiedOnline = pgpPublicKeyData.getOnlineVerificationFinished();
if (!keyVerifiedOffline && !keyVerifiedOnline) {
throw new Exception("Owner of the OpenPGP key " + pgpPublicKeyData.getFingerprint() + " not verified. Can not process with ETH address verification for " + ethereumAcc);
}
PGPPublicKey publicKey = PGPTools.readPublicKeyFromString(pgpPublicKeyData.getAsciiArmored().getValue());
result.setResult(PGPTools.verifyText(signedString, publicKey));
if (result.getResult()) {
Map<String, String> parameterMap = new HashMap<>();
parameterMap.put("acc", ethereumAcc);
parameterMap.put("fingerprint", unverifiedFingerprint);
// https://stackoverflow.com/questions/7784421/getting-unix-timestamp-from-date
Long keyCertificateValidUntilUnixTimeLong = pgpPublicKeyData.getExp().getTime() / 1000;
Integer keyCertificateValidUntilUnixTime = keyCertificateValidUntilUnixTimeLong.intValue();
parameterMap.put("keyCertificateValidUntil", keyCertificateValidUntilUnixTime.toString());
parameterMap.put("firstName", pgpPublicKeyData.getFirstName());
parameterMap.put("lastName", pgpPublicKeyData.getLastName());
if (pgpPublicKeyData.getUserBirthday() != null) {
// for testing with old keys only
Long birthDateUnixTimeLong = pgpPublicKeyData.getUserBirthday().getTime() / 1000;
Integer birthDateUnixTime = birthDateUnixTimeLong.intValue();
parameterMap.put("birthDate", birthDateUnixTime.toString());
} else {
parameterMap.put("birthDate", "null");
}
if (pgpPublicKeyData.getNationality() != null) {
// for testing with old keys only
parameterMap.put("nationality", pgpPublicKeyData.getNationality());
} else {
parameterMap.put("nationality", "null");
}
LOG.warning("parameterMap: ");
LOG.warning(GSON.toJson(parameterMap));
HTTPResponse httpResponseFromAddVerificationDataServlet = HttpService.makePostRequestWithParametersMapAndApiKey("https://tomcatweb3j.cryptonomica.net/addVerificationData", tomcatWeb3jAPIkey, parameterMap);
byte[] httpResponseContentBytesFromAddVerificationDataServlet = httpResponseFromAddVerificationDataServlet.getContent();
String httpResponseContentStringAddVerificationDataServlet = new String(httpResponseContentBytesFromAddVerificationDataServlet, StandardCharsets.UTF_8);
LOG.warning(httpResponseContentStringAddVerificationDataServlet);
result.setMessage(// tx receipt
httpResponseContentStringAddVerificationDataServlet);
}
LOG.warning("result:");
LOG.warning(GSON.toJson(result));
return result;
}
Aggregations