public IActionResult Sign(string keyName, [FromBody] string content) { if (string.IsNullOrWhiteSpace(content)) { return(BadRequest(ErrorResponse.Create("Content to sign can't be empty"))); } try { var result = _signService.Sign(content, keyName); return(Ok(result)); } catch (KeyNotFoundException keyEx) { _log.Error(keyEx, null, new { keyEx.KeyName }.ToJson()); return(BadRequest(ErrorResponse.Create(keyEx.Message))); } catch (Exception ex) { _log.Error(ex); } return(StatusCode((int)HttpStatusCode.InternalServerError)); }
public string SignCheckoutRequest(CheckoutRequest checkoutRequest) { string data = JsonConvert.SerializeObject(checkoutRequest, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore, DefaultValueHandling = DefaultValueHandling.Ignore }); var signature = _signService.Sign(data); return(Convert.ToBase64String(Encoding.UTF8.GetBytes(signature + "|" + data))); }
private void CommitFile(string filePath) { var status = repo.RetrieveStatus(filePath); Commands.Stage(repo, filePath); var commitSignature = repo.Config.BuildSignature(DateTimeOffset.Now); var message = $"{GetVerbFromGitFileStatus(status)} password store file {filePath}\n\n" + "This commit was automatically generated by pass-winmenu."; var tree = repo.ObjectDatabase.CreateTree(repo.Index); var sign = repo.Config.Get <bool>("commit.gpgsign"); if (sign?.Value ?? false) { Log.Send($"Generating GPG signature for {filePath}"); var keyId = repo.Config.Get <string>("user.signingkey"); if (string.IsNullOrWhiteSpace(keyId.Value)) { throw new GitException($"Unable to sign commit (no signing key set)."); } var commitBuffer = LibGit2Sharp.Commit.CreateBuffer( commitSignature, commitSignature, message, tree, new[] { repo.Head.Tip }, true, null); var gpgSignature = signService.Sign(commitBuffer, keyId.Value); var signedCommit = repo.ObjectDatabase.CreateCommitWithSignature(commitBuffer, gpgSignature); repo.Refs.UpdateTarget(repo.Refs.Head.ResolveToDirectReference(), signedCommit); } else { Log.Send($"Generating unsigned commit for {filePath}"); repo.Commit(message, commitSignature, commitSignature); } }