Search in sources :

Example 1 with RequestWrapper

use of net.iGap.request.RequestWrapper in project iGap-Android by KianIranian-STDG.

the class RegisterRepository method requestRegister.

private void requestRegister(String phoneNumber, RepositoryCallbackWithError<ErrorWithWaitTime> callback) {
    if (phoneNumber == null)
        return;
    this.phoneNumber = phoneNumber.replace("-", "");
    ProtoUserRegister.UserRegister.Builder builder = ProtoUserRegister.UserRegister.newBuilder();
    builder.setCountryCode(isoCode);
    builder.setPhoneNumber(Long.parseLong(this.phoneNumber));
    builder.setPreferenceMethodValue(ProtoUserRegister.UserRegisterResponse.Method.VERIFY_CODE_SMS.getNumber());
    builder.setRequest(ProtoRequest.Request.newBuilder().setId(HelperString.generateKey()));
    builder.setAppId(BuildConfig.APP_ID);
    RequestWrapper requestWrapper = new RequestWrapper(100, builder, new OnUserRegistration() {

        @Override
        public void onRegister(String userNameR, long userIdR, ProtoUserRegister.UserRegisterResponse.Method methodValue, List<Long> smsNumbersR, String regex, int verifyCodeDigitCount, String authorHashR, boolean callMethodSupported, long resendCodeDelay) {
            /*isCallMethodSupported = callMethodSupported;*/
            // because is new ui verification code number is 5 and number not not use it more
            /*digitCount = verifyCodeDigitCount;*/
            regexFetchCodeVerification = regex;
            userName = userNameR;
            userId = userIdR;
            authorHash = authorHashR;
            G.smsNumbers = smsNumbersR;
            method = methodValue;
            resendDelayTime = resendCodeDelay;
            callback.onSuccess();
        }

        @Override
        public void onRegisterError(int majorCode, int minorCode, int getWait) {
            G.handler.post(() -> callback.onError(new ErrorWithWaitTime(majorCode, minorCode, getWait)));
        }
    });
    try {
        RequestQueue.sendRequest(requestWrapper);
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
}
Also used : OnUserRegistration(net.iGap.observers.interfaces.OnUserRegistration) HelperString(net.iGap.helper.HelperString) ProtoUserRegister(net.iGap.proto.ProtoUserRegister) RequestWrapper(net.iGap.request.RequestWrapper)

Example 2 with RequestWrapper

use of net.iGap.request.RequestWrapper in project iGap-Android by KianIranian-STDG.

the class ConnectionSecuringResponse method handler.

@Override
public void handler() {
    super.handler();
    ProtoConnectionSecuring.ConnectionSecuringResponse.Builder builder = (ProtoConnectionSecuring.ConnectionSecuringResponse.Builder) message;
    G.currentTime = builder.getResponse().getTimestamp();
    String publicKey = builder.getPublicKey();
    int symmetricKeyLength = builder.getSymmetricKeyLength();
    G.serverHeartBeatTiming = (builder.getHeartbeatInterval() * 1000);
    String key = HelperString.generateKey(symmetricKeyLength);
    if (G.symmetricKey != null) {
        return;
    }
    G.symmetricKey = HelperString.generateSymmetricKey(key);
    G.symmetricKeyString = key;
    try {
        RSAPublicKey rsaPublicKeyServer = (RSAPublicKey) HelperString.getPublicKeyFromPemFormat(publicKey);
        PublicKey pubKeyServer = KeyFactory.getInstance("RSA").generatePublic(new RSAPublicKeySpec(rsaPublicKeyServer.getModulus(), rsaPublicKeyServer.getPublicExponent()));
        RSAPublicKey rsaPublicKeyClient = (RSAPublicKey) HelperString.getPublicKeyFromPemFormat(Config.PUBLIC_KEY_CLIENT);
        PublicKey pubKeyClient = KeyFactory.getInstance("RSA").generatePublic(new RSAPublicKeySpec(rsaPublicKeyClient.getModulus(), rsaPublicKeyClient.getPublicExponent()));
        byte[] encryption = AESCrypt.encryptSymmetricKey(pubKeyServer, pubKeyClient, G.symmetricKey.getEncoded(), builder.getSecondaryChunkSize());
        if (encryption != null) {
            ProtoConnectionSecuring.ConnectionSymmetricKey.Builder connectionSymmetricKey = ProtoConnectionSecuring.ConnectionSymmetricKey.newBuilder();
            connectionSymmetricKey.setSymmetricKey(ByteString.copyFrom(encryption));
            connectionSymmetricKey.setVersion(2);
            RequestWrapper requestWrapper = new RequestWrapper(2, connectionSymmetricKey);
            RequestQueue.sendRequest(requestWrapper);
        }
    } catch (IOException | NoSuchAlgorithmException | InvalidKeySpecException | IllegalAccessException e) {
        e.printStackTrace();
    }
}
Also used : PublicKey(java.security.PublicKey) RSAPublicKey(java.security.interfaces.RSAPublicKey) ByteString(com.google.protobuf.ByteString) HelperString(net.iGap.helper.HelperString) RSAPublicKeySpec(java.security.spec.RSAPublicKeySpec) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) RSAPublicKey(java.security.interfaces.RSAPublicKey) RequestWrapper(net.iGap.request.RequestWrapper) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) ProtoConnectionSecuring(net.iGap.proto.ProtoConnectionSecuring)

Example 3 with RequestWrapper

use of net.iGap.request.RequestWrapper in project iGap-Android by KianIranian-STDG.

the class RequestManager method requestQueueMapRemover.

private void requestQueueMapRemover(String key) {
    try {
        RequestWrapper requestWrapper = requestQueueMap.remove(key);
        if (requestWrapper != null) {
            if (requestWrapper.onResponse != null) {
                IG_RPC.TimeOut_error error = new IG_RPC.TimeOut_error();
                requestWrapper.onResponse.onReceived(null, error);
            } else {
                int actionId = requestWrapper.getActionId();
                String className = G.lookupMap.get(actionId + net.iGap.Config.LOOKUP_MAP_RESPONSE_OFFSET);
                String responseClassName = HelperClassNamePreparation.preparationResponseClassName(className);
                ProtoResponse.Response.Builder responseBuilder = ProtoResponse.Response.newBuilder();
                responseBuilder.setTimestamp((int) System.currentTimeMillis());
                responseBuilder.setId(key);
                responseBuilder.build();
                ProtoError.ErrorResponse.Builder errorBuilder = ProtoError.ErrorResponse.newBuilder();
                errorBuilder.setResponse(responseBuilder);
                errorBuilder.setMajorCode(5);
                errorBuilder.setMinorCode(1);
                errorBuilder.build();
                Class<?> c = Class.forName(responseClassName);
                Object object;
                try {
                    object = c.getConstructor(int.class, Object.class, Object.class).newInstance(actionId, errorBuilder, requestWrapper.identity);
                } catch (NoSuchMethodException e) {
                    object = c.getConstructor(int.class, Object.class, String.class).newInstance(actionId, errorBuilder, requestWrapper.identity);
                }
                Method setTimeoutMethod = object.getClass().getMethod("timeOut");
                setTimeoutMethod.invoke(object);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : HelperString(net.iGap.helper.HelperString) Method(java.lang.reflect.Method) GeneralSecurityException(java.security.GeneralSecurityException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ProtoResponse(net.iGap.proto.ProtoResponse) OnResponse(net.iGap.observers.interfaces.OnResponse) RequestWrapper(net.iGap.request.RequestWrapper)

Example 4 with RequestWrapper

use of net.iGap.request.RequestWrapper in project iGap-Android by KianIranian-STDG.

the class RequestManager method cancelRequest.

public boolean cancelRequest(String id) {
    RequestWrapper requestWrapper = requestQueueMap.get(id);
    if (requestWrapper == null)
        return false;
    requestQueueMap.remove(id);
    return true;
}
Also used : RequestWrapper(net.iGap.request.RequestWrapper)

Example 5 with RequestWrapper

use of net.iGap.request.RequestWrapper in project iGap-Android by KianIranian-STDG.

the class RequestManager method bindRequestToUniqueId.

public void bindRequestToUniqueId(final String reqId, final int uid) {
    networkQueue.postRunnable(() -> {
        RequestWrapper request = requestQueueMap.get(reqId);
        if (request != null) {
            List<RequestWrapper> list = new ArrayList<>();
            list.add(request);
            requestsByUId.put(uid, list);
        }
    });
}
Also used : ArrayList(java.util.ArrayList) RequestWrapper(net.iGap.request.RequestWrapper)

Aggregations

RequestWrapper (net.iGap.request.RequestWrapper)10 HelperString (net.iGap.helper.HelperString)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 GeneralSecurityException (java.security.GeneralSecurityException)2 ByteString (com.google.protobuf.ByteString)1 IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 PublicKey (java.security.PublicKey)1 RSAPublicKey (java.security.interfaces.RSAPublicKey)1 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)1 RSAPublicKeySpec (java.security.spec.RSAPublicKeySpec)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 OnResponse (net.iGap.observers.interfaces.OnResponse)1 OnUserRegistration (net.iGap.observers.interfaces.OnUserRegistration)1 OnUserVerification (net.iGap.observers.interfaces.OnUserVerification)1 ProtoConnectionSecuring (net.iGap.proto.ProtoConnectionSecuring)1