Ejemplo n.º 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);
            }
        }
Ejemplo n.º 2
0
        public object CredentialsInfo(InputCredentialsInfo inputCredentialsInfo)
        {
            JsonSerializer serializer  = new JsonSerializer();
            ErrorLogger    errorLogger = new ErrorLogger();
            string         baseURL     = _configuration.GetSection("Transsped").GetSection("BaseURL").Value;


            CredentialsInfoClient credentialsInfoClient = new CredentialsInfoClient(serializer, errorLogger, baseURL);
            object response = credentialsInfoClient.GetCredentialsInfo(_accessToken.GetAccessToken().access_token, inputCredentialsInfo);

            return(response);
        }
Ejemplo n.º 3
0
        public object GetCredentialsInfo(string access_token, InputCredentialsInfo inputCredentialsInfo)
        {
            RestRequest request = new RestRequest("credentialsinfo", Method.POST);

            request.AddParameter("Authorization", "Bearer " + access_token, ParameterType.HttpHeader);

            JsonSerializer serializer = new JsonSerializer();
            var            postData   = serializer.Serialize(inputCredentialsInfo);

            request.AddJsonBody(postData);

            IRestResponse response = Execute(request);

            // var data = serializer.Deserialize<object>(response);

            return(response.Content);
        }
        public virtual IActionResult CredentialsInfo([FromBody] InputCredentialsInfo body)
        {
            //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
            // return StatusCode(200, default(OutputCredentialsInfo));

            //TODO: Uncomment the next line to return response 400 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
            // return StatusCode(400);
            string exampleJson = null;

            exampleJson = "{\n  \"key\" : {\n    \"status\" : \"enabled\",\n    \"algo\" : [ \"1.2.840.113549.1.1.1\", \"0.4.0.127.0.7.1.1.4.1.3\" ],\n    \"len\" : 2048\n  },\n  \"cert\" : {\n    \"status\" : \"valid\",\n    \"certificates\" : [ \"<Base64-encoded_X.509_end_entity_certificate>\", \"<Base64-encoded_X.509_intermediate_CA_certificate>\", \"<Base64-encoded_X.509_root_CA_certificate>\" ],\n    \"issuerDN\" : \"<X.500_issuer_DN_printable_string>\",\n    \"serialNumber\" : \"5AAC41CD8FA22B953640\",\n    \"subjectDN\" : \"<X.500_subject_DN_printable_string>\",\n    \"validFrom\" : \"20180101100000Z\",\n    \"validTo\" : \"20190101095959Z\",\n    \"authMode\" : \"explicit\",\n    \"PIN\" : {\n      \"presence\" : \"true\",\n      \"label\" : \"PIN\",\n      \"description\" : \"Please enter the signature PIN\"\n    },\n    \"OTP\" : {\n      \"presence\" : \"true\",\n      \"type\" : \"offline\",\n      \"ID\" : \"MB01-K741200\",\n      \"provider\" : \"totp\",\n      \"format\" : \"N\",\n      \"label\" : \"Mobile OTP\",\n      \"description\" : \"Please enter the 6 digit code you received by SMS\"\n    },\n    \"multisign\" : 5,\n    \"lang\" : \"en-US\"\n  }\n}";

            var example = exampleJson != null
                        ? JsonConvert.DeserializeObject <OutputCredentialsInfo>(exampleJson)
                        : default(OutputCredentialsInfo);            //TODO: Change the data returned

            return(new ObjectResult(example));
        }
Ejemplo n.º 5
0
        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);
            }
        }
Ejemplo n.º 6
0
        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);
        }