Search in sources :

Example 36 with ApiMethod

use of com.google.api.server.spi.config.ApiMethod in project cryptonomica by Cryptonomica.

the class VerificationAPI method getVerificationByWebSafeString.

// end: getVerificationByID
/* --- Get verification info by web-safe key string: */
@ApiMethod(name = "getVerificationByWebSafeString", path = "getVerificationByWebSafeString", httpMethod = ApiMethod.HttpMethod.GET)
@SuppressWarnings("unused")
public VerificationGeneralView getVerificationByWebSafeString(final HttpServletRequest httpServletRequest, final User googleUser, @Named("verificationWebSafeString") final String verificationWebSafeString) throws // see: https://cloud.google.com/appengine/docs/java/endpoints/exceptions
UnauthorizedException, BadRequestException, NotFoundException {
    /* --- Check authorization: */
    CryptonomicaUser cryptonomicaUser = UserTools.ensureCryptonomicaRegisteredUser(googleUser);
    /* --- Check input: */
    if (verificationWebSafeString == null || verificationWebSafeString.equals("")) {
        throw new BadRequestException("Verification ID missing");
    }
    /* --- Load verification entity from DS: */
    Key<Verification> verificationKey = Key.create(verificationWebSafeString);
    Verification verification = ofy().load().key(verificationKey).now();
    if (verification == null) {
        throw new NotFoundException("Verification info not found");
    }
    /* --- Create new verification info representation: */
    VerificationGeneralView verificationGeneralView = new VerificationGeneralView(verification);
    LOG.warning(new Gson().toJson(verificationGeneralView));
    return verificationGeneralView;
}
Also used : BadRequestException(com.google.api.server.spi.response.BadRequestException) NotFoundException(com.google.api.server.spi.response.NotFoundException) Gson(com.google.gson.Gson) Verification(net.cryptonomica.entities.Verification) VerificationGeneralView(net.cryptonomica.returns.VerificationGeneralView) CryptonomicaUser(net.cryptonomica.entities.CryptonomicaUser) ApiMethod(com.google.api.server.spi.config.ApiMethod)

Example 37 with ApiMethod

use of com.google.api.server.spi.config.ApiMethod in project cryptonomica by Cryptonomica.

the class ArbitratorsAPI method addArbitrator.

@ApiMethod(name = "addArbitrator", path = "addArbitrator", httpMethod = ApiMethod.HttpMethod.POST)
@SuppressWarnings("unused")
public ArbitratorGeneralView addArbitrator(final User googleUser, final AddArbitratorForm addArbitratorForm) throws Exception {
    /* --- Ensure cryptonomica officer: */
    UserTools.ensureCryptonomicaOfficer(googleUser);
    /* --- Check form: */
    if (addArbitratorForm.getId() == null) {
        throw new IllegalArgumentException("User ID is missing");
    }
    // create arbitrator from form:
    Arbitrator arbitrator = new Arbitrator(addArbitratorForm);
    // save arbitrator in DS:
    Key<Arbitrator> arbitratorKey = ofy().save().entity(arbitrator).now();
    // add info to CryptonomicaUser
    CryptonomicaUser arbitratorCryptonomicaUser = ofy().load().key(Key.create(CryptonomicaUser.class, arbitrator.getId())).now();
    arbitratorCryptonomicaUser.setArbitrator(Boolean.TRUE);
    ofy().save().entity(arbitratorCryptonomicaUser).now();
    // create ArbitratorGeneralView
    ArbitratorGeneralView arbitratorGeneralView = new ArbitratorGeneralView(arbitratorCryptonomicaUser, arbitrator);
    LOG.warning("new arbitrator created: " + new Gson().toJson(arbitratorGeneralView));
    return arbitratorGeneralView;
}
Also used : Gson(com.google.gson.Gson) Arbitrator(net.cryptonomica.entities.Arbitrator) CryptonomicaUser(net.cryptonomica.entities.CryptonomicaUser) ArbitratorGeneralView(net.cryptonomica.returns.ArbitratorGeneralView) ApiMethod(com.google.api.server.spi.config.ApiMethod)

Example 38 with ApiMethod

use of com.google.api.server.spi.config.ApiMethod in project cryptonomica by Cryptonomica.

the class CryptonomicaUserAPI method getMyUserData.

// end of ensureNewCryptonomicaUser @ApiMethod
/* ----- */
@ApiMethod(name = "getMyUserData", path = "getMyUserData", httpMethod = ApiMethod.HttpMethod.POST)
@SuppressWarnings("unused")
public UserProfileGeneralView getMyUserData(final HttpServletRequest httpServletRequest, final User googleUser) {
    // 
    UserProfileGeneralView userProfileGeneralView = null;
    CryptonomicaUser cryptonomicaUser = null;
    // 
    if (googleUser == null) {
        userProfileGeneralView = new UserProfileGeneralView();
        userProfileGeneralView.setLoggedIn(false);
        return userProfileGeneralView;
    }
    try {
        cryptonomicaUser = ofy().load().key(Key.create(CryptonomicaUser.class, googleUser.getUserId())).now();
    } catch (Exception e) {
        LOG.warning(e.getMessage());
    }
    if (cryptonomicaUser == null) {
        userProfileGeneralView = new UserProfileGeneralView();
        userProfileGeneralView.setLoggedIn(true);
        userProfileGeneralView.setRegisteredCryptonomicaUser(false);
        return userProfileGeneralView;
    } else {
        userProfileGeneralView = new UserProfileGeneralView(cryptonomicaUser);
        userProfileGeneralView.setLoggedIn(true);
        userProfileGeneralView.setRegisteredCryptonomicaUser(true);
        return userProfileGeneralView;
    }
}
Also used : UserProfileGeneralView(net.cryptonomica.returns.UserProfileGeneralView) CryptonomicaUser(net.cryptonomica.entities.CryptonomicaUser) ApiMethod(com.google.api.server.spi.config.ApiMethod)

Example 39 with ApiMethod

use of com.google.api.server.spi.config.ApiMethod 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;
}
Also used : PGPPublicKeyData(net.cryptonomica.entities.PGPPublicKeyData) AppSettings(net.cryptonomica.entities.AppSettings) HashMap(java.util.HashMap) HTTPResponse(com.google.appengine.api.urlfetch.HTTPResponse) PGPPublicKey(org.bouncycastle.openpgp.PGPPublicKey) BooleanWrapperObject(net.cryptonomica.returns.BooleanWrapperObject) CryptonomicaUser(net.cryptonomica.entities.CryptonomicaUser) VerificationRequestDataFromSC(net.cryptonomica.entities.VerificationRequestDataFromSC) UnauthorizedException(com.google.api.server.spi.response.UnauthorizedException) ApiMethod(com.google.api.server.spi.config.ApiMethod)

Example 40 with ApiMethod

use of com.google.api.server.spi.config.ApiMethod in project cryptonomica by Cryptonomica.

the class EthNodeAPI method getVerificationDataFromSmartContract.

// 
@ApiMethod(name = "getVerificationFromSC", path = "getVerificationFromSC", httpMethod = ApiMethod.HttpMethod.GET)
@SuppressWarnings("unused")
public VerificationStruct getVerificationDataFromSmartContract(// final HttpServletRequest httpServletRequest,
final User googleUser, @Named("ethereumAcc") final String ethereumAcc) throws IllegalArgumentException, UnauthorizedException {
    // 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 = "/getVerification";
    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);
    // LOG.warning("httpResponse: " + new Gson().toJson(httpResponse));
    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);
    VerificationStruct verificationStruct = GSON.fromJson(httpResponseContentString, VerificationStruct.class);
    /* header:
        content-type:  application/json;charset=utf-8
        body:
        {
            "fingerprint": "",
            "keyCertificateValidUntil": 0,
            "firstName": "",
            "lastName": "",
            "birthDate": 0,
            "nationality": "",
            "verificationAddedOn": 0,
            "revokedOn": 0
        }
        */
    return verificationStruct;
}
Also used : VerificationStruct(net.cryptonomica.returns.VerificationStruct) AppSettings(net.cryptonomica.entities.AppSettings) HTTPResponse(com.google.appengine.api.urlfetch.HTTPResponse) CryptonomicaUser(net.cryptonomica.entities.CryptonomicaUser) ApiMethod(com.google.api.server.spi.config.ApiMethod)

Aggregations

ApiMethod (com.google.api.server.spi.config.ApiMethod)54 CryptonomicaUser (net.cryptonomica.entities.CryptonomicaUser)19 Gson (com.google.gson.Gson)16 UserData (com.google.samples.apps.iosched.server.userdata.db.UserData)10 PGPPublicKeyData (net.cryptonomica.entities.PGPPublicKeyData)10 ArrayList (java.util.ArrayList)9 StringWrapperObject (net.cryptonomica.returns.StringWrapperObject)9 NotFoundException (com.google.api.server.spi.response.NotFoundException)8 BadRequestException (com.google.api.server.spi.response.BadRequestException)7 UnauthorizedException (com.google.api.server.spi.response.UnauthorizedException)7 Queue (com.google.appengine.api.taskqueue.Queue)7 HTTPResponse (com.google.appengine.api.urlfetch.HTTPResponse)6 Device (com.google.samples.apps.iosched.server.gcm.db.models.Device)6 MessageSender (com.google.samples.apps.iosched.server.gcm.device.MessageSender)5 AppSettings (net.cryptonomica.entities.AppSettings)5 PGPPublicKeyGeneralView (net.cryptonomica.returns.PGPPublicKeyGeneralView)5 UserProfileGeneralView (net.cryptonomica.returns.UserProfileGeneralView)5 BookmarkedSession (com.google.samples.apps.iosched.server.userdata.db.BookmarkedSession)4 BooleanWrapperObject (net.cryptonomica.returns.BooleanWrapperObject)4 PGPPublicKey (org.bouncycastle.openpgp.PGPPublicKey)4