Exemple #1
0
        private TElX509Certificate LoadCertificate(string credentialsID, string access_token)
        {
            JsonSerializer        serializer     = new JsonSerializer();
            ErrorLogger           errorLogger    = new ErrorLogger();
            CredentialsInfoClient credInfoClient = new CredentialsInfoClient(serializer, errorLogger, baseURL);

            InputCredentialsInfo credentialsInfo = new InputCredentialsInfo()
            {
                credentialID = credentialsID
            };
            string temp = credInfoClient.GetCredentialsInfo(access_token, credentialsInfo).ToString();

            // string temp = serializer.Serialize(outputCredentials);
            if (!temp.Contains("error") && temp != "")
            {
                OutputCredentialsInfo output = serializer.Deserialize <OutputCredentialsInfo>(temp);

                string certificate = output.cert.certificates.FirstOrDefault();

                TElX509Certificate cert    = new TElX509Certificate();
                byte[]             certBuf = Encoding.UTF8.GetBytes(certificate);
                int r = cert.LoadFromBufferAuto(certBuf, 0, certBuf.Length, "");

                if (r != 0)
                {
                    throw new Exception("Certificate read error: " + r.ToString());
                }

                return(cert);
            }
            else
            {
                return(null);
            }
        }
        private TElMemoryCertStorage LoadCertificate(string credentialsID, string access_token)
        {
            //credentialsInfo
            JsonSerializer        serializer     = new JsonSerializer();
            ErrorLogger           errorLogger    = new ErrorLogger();
            CredentialsInfoClient credInfoClient = new CredentialsInfoClient(serializer, errorLogger, "https://msign-test.transsped.ro/csc/v0/");

            InputCredentialsInfo credentialsInfo = new InputCredentialsInfo()
            {
                credentialID = credentialsID
            };
            object outputCredentials = credInfoClient.GetCredentialsInfo(access_token, credentialsInfo);

            string temp = serializer.Serialize(outputCredentials);

            if (!temp.Contains("error"))
            {
                OutputCredentialsInfo output = serializer.Deserialize <OutputCredentialsInfo>(temp);

                string certificate = output.cert.certificates.FirstOrDefault();

                TElX509Certificate cert    = new TElX509Certificate();
                byte[]             certBuf = Encoding.UTF8.GetBytes(certificate);
                int r = cert.LoadFromBufferAuto(certBuf, 0, certBuf.Length, "");

                if (r != 0)
                {
                    throw new Exception("Certificate read error: " + r.ToString());
                }

                TElMemoryCertStorage storage = new TElMemoryCertStorage();
                storage.Add(cert, true);

                return(storage);
            }
            else
            {
                return(null);
            }
        }
        public object Credentials(InputCredentialsList inputCredentialsList)
        {
            JsonSerializer serializer  = new JsonSerializer();
            ErrorLogger    errorLogger = new ErrorLogger();
            string         baseURL     = _configuration.GetSection("Transsped").GetSection("BaseURL").Value;

            CredentialsListClient credentialsListClient = new CredentialsListClient(serializer, errorLogger, baseURL);

            Microsoft.Extensions.Primitives.StringValues value;
            string access_token = "";

            if (Request.Headers.TryGetValue("Authorization", out value))
            {
                access_token = value.ToString().Replace("Bearer ", "");
            }
            else
            {
                OutputError error = new OutputError()
                {
                    error             = "invalid_access_token",
                    error_description = "Invalid access_token"
                };
                return(serializer.Serialize(error));
            }
            object response = credentialsListClient.GetCredentialsList(access_token, inputCredentialsList);
            var    credList = serializer.Serialize(response);
            OutputCredentialsList    outputCredentialsList = serializer.Deserialize <OutputCredentialsList>(credList);
            List <OutputCredentials> userCredInfo          = new List <OutputCredentials>();

            if (outputCredentialsList != null && outputCredentialsList.credentialIDs != null)
            {
                foreach (var credID in outputCredentialsList.credentialIDs)
                {
                    InputCredentialsInfo inputCredentialsInfo = new InputCredentialsInfo()
                    {
                        credentialID = credID
                    };

                    CredentialsInfoClient credentialsInfoClient = new CredentialsInfoClient(serializer, errorLogger, baseURL);
                    var credInfoResponse = serializer.Serialize(credentialsInfoClient.GetCredentialsInfo(access_token, inputCredentialsInfo));
                    if (!credInfoResponse.Contains("error"))
                    {
                        OutputCredentialsInfo outputCredentialsInfo = serializer.Deserialize <OutputCredentialsInfo>(credInfoResponse);
                        OutputCredentials     tempOutputCred        = new OutputCredentials();
                        tempOutputCred.credentialID = credID;
                        tempOutputCred.authMode     = outputCredentialsInfo.authMode;
                        tempOutputCred.cert         = outputCredentialsInfo.cert;
                        tempOutputCred.description  = outputCredentialsInfo.description;
                        tempOutputCred.key          = outputCredentialsInfo.key;
                        tempOutputCred.lang         = outputCredentialsInfo.lang;
                        tempOutputCred.multisign    = outputCredentialsInfo.multisign;
                        tempOutputCred.OTP          = outputCredentialsInfo.OTP;
                        tempOutputCred.PIN          = outputCredentialsInfo.PIN;
                        tempOutputCred.SCAL         = outputCredentialsInfo.SCAL;

                        userCredInfo.Add(tempOutputCred);
                    }
                }
            }
            //pentru fiecare id din lista de credentiale sa returnez tot certificatul
            return(userCredInfo);
        }