Search in sources :

Example 6 with PGPPublicKeyData

use of net.cryptonomica.entities.PGPPublicKeyData in project cryptonomica by Cryptonomica.

the class PGPPublicKeyAPI method getPGPPublicKeyByFingerprint.

@ApiMethod(name = "getPGPPublicKeyByFingerprint", path = "getPGPPublicKeyByFingerprint", httpMethod = ApiMethod.HttpMethod.GET)
@SuppressWarnings("unused")
public // get key by by fingerprint
PGPPublicKeyGeneralView getPGPPublicKeyByFingerprint(final User googleUser, @Named("fingerprint") final String fingerprint) throws Exception {
    /* Log request: */
    LOG.warning("Request: @Named(\"fingerprint\") : " + fingerprint);
    /* Check authorization: */
    UserTools.ensureCryptonomicaRegisteredUser(googleUser);
    // GET Key from DataBase by fingerprint:
    PGPPublicKeyData pgpPublicKeyData = PGPTools.getPGPPublicKeyDataFromDataBaseByFingerprint(fingerprint);
    // make key representation, return result
    PGPPublicKeyGeneralView pgpPublicKeyGeneralView = new PGPPublicKeyGeneralView(pgpPublicKeyData);
    LOG.warning("Result: " + GSON.toJson(pgpPublicKeyGeneralView));
    return pgpPublicKeyGeneralView;
}
Also used : PGPPublicKeyData(net.cryptonomica.entities.PGPPublicKeyData) PGPPublicKeyGeneralView(net.cryptonomica.returns.PGPPublicKeyGeneralView) ApiMethod(com.google.api.server.spi.config.ApiMethod)

Example 7 with PGPPublicKeyData

use of net.cryptonomica.entities.PGPPublicKeyData in project cryptonomica by Cryptonomica.

the class PGPPublicKeyAPI method getPGPPublicKeyByWebSafeString.

@ApiMethod(name = "getPGPPublicKeyByWebSafeString", path = "getPGPPublicKeyByWebSafeString", httpMethod = ApiMethod.HttpMethod.GET)
@SuppressWarnings("unused")
public // get key by by WebSafeString
PGPPublicKeyGeneralView getPGPPublicKeyByWebSafeString(final User googleUser, @Named("websafestring") final String webSafeString) throws Exception {
    /* Check authorization */
    UserTools.ensureCryptonomicaRegisteredUser(googleUser);
    /* Validate form: */
    LOG.warning("@Named(\"websafestring\") : " + webSafeString);
    if (webSafeString == null || webSafeString.length() < 1) {
        throw new Exception("Invalid public key in request");
    }
    /* Load PGPPublicKeyData from DB*/
    Key<PGPPublicKeyData> pgpPublicKeyDataKey = Key.create(webSafeString);
    PGPPublicKeyData pgpPublicKeyData = null;
    try {
        pgpPublicKeyData = ofy().load().key(pgpPublicKeyDataKey).now();
    } catch (Exception e) {
        LOG.warning("Load PGPPublicKeyData from DB failed: " + e.getMessage());
    }
    if (pgpPublicKeyData == null) {
        LOG.warning("pgpPublicKeyData == null");
        throw new Exception("Public PGP key not found");
    }
    return new PGPPublicKeyGeneralView(pgpPublicKeyData);
}
Also used : PGPPublicKeyData(net.cryptonomica.entities.PGPPublicKeyData) PGPPublicKeyGeneralView(net.cryptonomica.returns.PGPPublicKeyGeneralView) ApiMethod(com.google.api.server.spi.config.ApiMethod)

Example 8 with PGPPublicKeyData

use of net.cryptonomica.entities.PGPPublicKeyData in project cryptonomica by Cryptonomica.

the class PGPPublicKeyAPI method searchPGPPublicKeys.

@ApiMethod(name = "searchPGPPublicKeys", path = "searchPGPPublicKeys", httpMethod = ApiMethod.HttpMethod.POST)
@SuppressWarnings("unused")
public // 4) by first and last names
SearchPGPPublicKeysReturn searchPGPPublicKeys(// final HttpServletRequest httpServletRequest,
final User googleUser, final SearchPGPPublicKeysForm searchPGPPublicKeysForm) throws Exception {
    // authorization
    UserTools.ensureCryptonomicaRegisteredUser(googleUser);
    // 
    String fingerprint = searchPGPPublicKeysForm.getFingerprint();
    String keyID = searchPGPPublicKeysForm.getKeyID();
    String userID = searchPGPPublicKeysForm.getUserID();
    String firstName = searchPGPPublicKeysForm.getFirstName();
    String lastName = searchPGPPublicKeysForm.getLastName();
    String cryptonomicaUserId = searchPGPPublicKeysForm.getCryptonomicaUserId();
    Email userEmail = null;
    if (searchPGPPublicKeysForm.getUserEmail() != null) {
        userEmail = new Email(searchPGPPublicKeysForm.getUserEmail());
    }
    List<? extends PGPPublicKeyData> result;
    if (fingerprint != null) {
        result = ofy().load().type(PGPPublicKeyData.class).filter("fingerprint", fingerprint).list();
    } else if (keyID != null) {
        result = ofy().load().type(PGPPublicKeyData.class).filter("keyID", keyID).list();
    } else if (userEmail != null) {
        result = ofy().load().type(PGPPublicKeyData.class).filter("userEmail", userEmail).list();
    } else if (firstName != null && lastName != null) {
        result = ofy().load().type(PGPPublicKeyData.class).filter("firstName", firstName).filter("lastName", lastName).list();
    } else if (cryptonomicaUserId != null) {
        result = ofy().load().type(PGPPublicKeyData.class).filter("cryptonomicaUserId", cryptonomicaUserId).list();
    } else {
        throw new Exception("invalid search query: " + new Gson().toJson(searchPGPPublicKeysForm));
    }
    SearchPGPPublicKeysReturn searchPGPPublicKeysReturn = new SearchPGPPublicKeysReturn();
    if (result.size() > 0) {
        searchPGPPublicKeysReturn.PublicKeyDatasToGeneralViews(new ArrayList<PGPPublicKeyData>(result));
        searchPGPPublicKeysReturn.setMessageToUser("search results:");
    } else {
        searchPGPPublicKeysReturn.PublicKeyDatasToGeneralViews(new ArrayList<PGPPublicKeyData>());
        searchPGPPublicKeysReturn.setMessageToUser("no records found");
    }
    return searchPGPPublicKeysReturn;
}
Also used : PGPPublicKeyData(net.cryptonomica.entities.PGPPublicKeyData) Email(com.google.appengine.api.datastore.Email) SearchPGPPublicKeysReturn(net.cryptonomica.returns.SearchPGPPublicKeysReturn) Gson(com.google.gson.Gson) ApiMethod(com.google.api.server.spi.config.ApiMethod)

Example 9 with PGPPublicKeyData

use of net.cryptonomica.entities.PGPPublicKeyData in project cryptonomica by Cryptonomica.

the class UserSearchAndViewAPI method getMyProfile.

// end of getUserProfileById @ApiMethod
@// <<< --- not used, use getMyUserData in CryptonomicaUserAPI
ApiMethod(name = "getMyProfile", path = "getMyProfile", httpMethod = ApiMethod.HttpMethod.POST)
@SuppressWarnings("unused")
public // returns list of user profiles
UserProfileGeneralView getMyProfile(final User googleUser) throws Exception {
    // ensure authorization
    UserTools.ensureCryptonomicaRegisteredUser(googleUser);
    // 
    Key<CryptonomicaUser> myKey = Key.create(CryptonomicaUser.class, googleUser.getUserId());
    CryptonomicaUser profile = ofy().load().key(myKey).now();
    UserProfileGeneralView userProfileGeneralView = new UserProfileGeneralView(profile);
    List<PGPPublicKeyData> pgpPublicKeyDataList = ofy().load().type(PGPPublicKeyData.class).ancestor(myKey).list();
    ArrayList<PGPPublicKeyGeneralView> pgpPublicKeyGeneralViews = new ArrayList<>();
    for (PGPPublicKeyData pgpPublicKeyData : pgpPublicKeyDataList) {
        pgpPublicKeyGeneralViews.add(new PGPPublicKeyGeneralView(pgpPublicKeyData));
    }
    userProfileGeneralView.setPgpPublicKeyGeneralViews(pgpPublicKeyGeneralViews);
    return userProfileGeneralView;
}
Also used : UserProfileGeneralView(net.cryptonomica.returns.UserProfileGeneralView) PGPPublicKeyData(net.cryptonomica.entities.PGPPublicKeyData) PGPPublicKeyGeneralView(net.cryptonomica.returns.PGPPublicKeyGeneralView) ArrayList(java.util.ArrayList) CryptonomicaUser(net.cryptonomica.entities.CryptonomicaUser) ApiMethod(com.google.api.server.spi.config.ApiMethod)

Example 10 with PGPPublicKeyData

use of net.cryptonomica.entities.PGPPublicKeyData in project cryptonomica by Cryptonomica.

the class UserSearchAndViewAPI method getUserProfileById.

// end of generalSearchUserProfiles @ApiMethod
@ApiMethod(name = "getUserProfileById", path = "getUserProfileById", httpMethod = ApiMethod.HttpMethod.GET)
@SuppressWarnings("unused")
public // returns list of user profiles
UserProfileGeneralView getUserProfileById(final User googleUser, @Named("id") final String id) throws Exception {
    /* Check authorization: */
    UserTools.ensureCryptonomicaRegisteredUser(googleUser);
    /* Validate form: */
    LOG.warning("@Named(\"id\"): " + id);
    if (id == null || id.length() < 1) {
        throw new Exception("User id is empty");
    }
    /* Load CryptonomicaUser from DB */
    // create key
    Key<CryptonomicaUser> cryptonomicaUserKey = Key.create(CryptonomicaUser.class, id);
    // get user with given Id from DB:
    CryptonomicaUser profile = ofy().load().key(cryptonomicaUserKey).now();
    // check result:
    if (profile == null) {
        LOG.warning("User with not found");
        throw new Exception("User not found");
    }
    /* Create UserProfileGeneralView object to return */
    // find his public keys:
    List<PGPPublicKeyData> pgpPublicKeyDataList = ofy().load().type(PGPPublicKeyData.class).filter("cryptonomicaUserId", id).list();
    // check keys found, if no webSafeString add and store in DB :
    LOG.info("pgpPublicKeyDataList: " + new Gson().toJson(pgpPublicKeyDataList));
    for (PGPPublicKeyData k : pgpPublicKeyDataList) {
        if (k.getWebSafeString() == null) {
            if (k.getCryptonomicaUserKey() != null) {
                k.setWebSafeString(Key.create(k.getCryptonomicaUserKey(), PGPPublicKeyData.class, k.getFingerprint()).toWebSafeString());
            } else {
                // for old keys without parent
                k.setWebSafeString(Key.create(PGPPublicKeyData.class, k.getFingerprint()).toWebSafeString());
            }
            // async !
            ofy().save().entity(k);
        }
    }
    // create obj to return:
    UserProfileGeneralView userProfileGeneralView = new UserProfileGeneralView(profile, pgpPublicKeyDataList);
    LOG.warning("userProfileGeneralView: " + userProfileGeneralView.toJson());
    return userProfileGeneralView;
}
Also used : UserProfileGeneralView(net.cryptonomica.returns.UserProfileGeneralView) PGPPublicKeyData(net.cryptonomica.entities.PGPPublicKeyData) Gson(com.google.gson.Gson) CryptonomicaUser(net.cryptonomica.entities.CryptonomicaUser) ApiMethod(com.google.api.server.spi.config.ApiMethod)

Aggregations

PGPPublicKeyData (net.cryptonomica.entities.PGPPublicKeyData)12 ApiMethod (com.google.api.server.spi.config.ApiMethod)10 CryptonomicaUser (net.cryptonomica.entities.CryptonomicaUser)6 PGPPublicKeyGeneralView (net.cryptonomica.returns.PGPPublicKeyGeneralView)5 Gson (com.google.gson.Gson)4 PGPPublicKey (org.bouncycastle.openpgp.PGPPublicKey)4 ArrayList (java.util.ArrayList)3 UserProfileGeneralView (net.cryptonomica.returns.UserProfileGeneralView)3 IOException (java.io.IOException)2 Date (java.util.Date)2 SearchPGPPublicKeysReturn (net.cryptonomica.returns.SearchPGPPublicKeysReturn)2 UnauthorizedException (com.google.api.server.spi.response.UnauthorizedException)1 Email (com.google.appengine.api.datastore.Email)1 Queue (com.google.appengine.api.taskqueue.Queue)1 HTTPResponse (com.google.appengine.api.urlfetch.HTTPResponse)1 GsonBuilder (com.google.gson.GsonBuilder)1 Key (com.googlecode.objectify.Key)1 HashMap (java.util.HashMap)1 AppSettings (net.cryptonomica.entities.AppSettings)1 Login (net.cryptonomica.entities.Login)1