Beispiel #1
0
        public async Task <IActionResult> CreateNewIdentity([FromBody] IdentityRequest request)
        {
            NewIdentityModel iden = new NewIdentityModel();

            iden.NameSpace  = request.NameSpace;
            iden.Identifier = request.Identifier;
            await _ndid.CreateNewIdentity(iden);

            return(NoContent());
        }
Beispiel #2
0
        public async Task CreateNewIdentity(NewIdentityModel iden)
        {
            // 1. generate new keypair
            NewIdentityModel newIdentity = new NewIdentityModel();

            newIdentity.NameSpace  = iden.NameSpace;
            newIdentity.Identifier = iden.Identifier;
            string sid = newIdentity.NameSpace + "-" + newIdentity.Identifier;
            await _dpki.GenNewKey(sid);

            // 2. read public key
            string pubKey = await _dpki.GetPubKey(sid);

            // 3. construct new identity api request
            newIdentity.AccessorType   = "RSA";
            newIdentity.AccessorPubKey = pubKey;
            newIdentity.ReferenceId    = Guid.NewGuid().ToString();
            newIdentity.CallbackUrl    = new Uri(new Uri(_config.GetCallbackPath()), "api/callback/identity").ToString();
            newIdentity.IAL            = 2.3m;
            _db.SaveAccessorSign(newIdentity.ReferenceId, sid);
            _db.SaveReference(newIdentity.ReferenceId, "sid", sid);
            // 4. check response from api reqeust
            using (HttpClient client = new HttpClient())
            {
                Uri url = new Uri(_apiServerAddress + "/v2/identity");
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(
                    new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                string        jsonContent = JsonConvert.SerializeObject(newIdentity);
                StringContent content     = new StringContent(jsonContent, Encoding.UTF8, "application/json");
                var           result      = client.PostAsync(url, content).Result;
                string        resultJson  = await result.Content.ReadAsStringAsync();

                if (result.IsSuccessStatusCode)
                {
                    NDIDCallbackIdentityModel model = JsonConvert.DeserializeObject <NDIDCallbackIdentityModel>(resultJson);
                    _db.SaveReference(newIdentity.ReferenceId, "accessor_id", model.AccessorId);
                    _db.SaveReference(newIdentity.ReferenceId, "request_id", model.RequestId);
                }
                else
                {
                    NDIDCallbackRequestModel model = JsonConvert.DeserializeObject <NDIDCallbackRequestModel>(resultJson);
                    throw new ApplicationException(model.Error.Message);
                }
            }
        }