MCPcopy Index your code
hub / github.com/git/git / sign_buffer_ssh

Function sign_buffer_ssh

gpg-interface.c:1058–1153  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1056}
1057
1058static int sign_buffer_ssh(struct strbuf *buffer, struct strbuf *signature,
1059 const char *signing_key)
1060{
1061 struct child_process signer = CHILD_PROCESS_INIT;
1062 int ret = -1;
1063 size_t bottom, keylen;
1064 struct strbuf signer_stderr = STRBUF_INIT;
1065 struct tempfile *key_file = NULL, *buffer_file = NULL;
1066 char *ssh_signing_key_file = NULL;
1067 struct strbuf ssh_signature_filename = STRBUF_INIT;
1068 const char *literal_key = NULL;
1069 int literal_ssh_key = 0;
1070
1071 if (!signing_key || signing_key[0] == '\0')
1072 return error(
1073 _("user.signingKey needs to be set for ssh signing"));
1074
1075 if (is_literal_ssh_key(signing_key, &literal_key)) {
1076 /* A literal ssh key */
1077 literal_ssh_key = 1;
1078 key_file = mks_tempfile_t(".git_signing_key_tmpXXXXXX");
1079 if (!key_file)
1080 return error_errno(
1081 _("could not create temporary file"));
1082 keylen = strlen(literal_key);
1083 if (write_in_full(key_file->fd, literal_key, keylen) < 0 ||
1084 close_tempfile_gently(key_file) < 0) {
1085 error_errno(_("failed writing ssh signing key to '%s'"),
1086 key_file->filename.buf);
1087 goto out;
1088 }
1089 ssh_signing_key_file = xstrdup(key_file->filename.buf);
1090 } else {
1091 /* We assume a file */
1092 ssh_signing_key_file = interpolate_path(signing_key, 1);
1093 }
1094
1095 buffer_file = mks_tempfile_t(".git_signing_buffer_tmpXXXXXX");
1096 if (!buffer_file) {
1097 error_errno(_("could not create temporary file"));
1098 goto out;
1099 }
1100
1101 if (write_in_full(buffer_file->fd, buffer->buf, buffer->len) < 0 ||
1102 close_tempfile_gently(buffer_file) < 0) {
1103 error_errno(_("failed writing ssh signing key buffer to '%s'"),
1104 buffer_file->filename.buf);
1105 goto out;
1106 }
1107
1108 strvec_pushl(&signer.args, use_format->program,
1109 "-Y", "sign",
1110 "-n", "git",
1111 "-f", ssh_signing_key_file,
1112 NULL);
1113 if (literal_ssh_key)
1114 strvec_push(&signer.args, "-U");
1115 strvec_push(&signer.args, buffer_file->filename.buf);

Callers

nothing calls this directly

Calls 15

errorFunction · 0.85
is_literal_ssh_keyFunction · 0.85
mks_tempfile_tFunction · 0.85
error_errnoFunction · 0.85
write_in_fullFunction · 0.85
close_tempfile_gentlyFunction · 0.85
xstrdupFunction · 0.85
interpolate_pathFunction · 0.85
strvec_pushlFunction · 0.85
strvec_pushFunction · 0.85
sigchain_pushFunction · 0.85
pipe_commandFunction · 0.85

Tested by

no test coverage detected