| 351 | } |
| 352 | |
| 353 | static int generate_push_cert(struct strbuf *req_buf, |
| 354 | const struct ref *remote_refs, |
| 355 | struct send_pack_args *args, |
| 356 | const char *cap_string, |
| 357 | const char *push_cert_nonce) |
| 358 | { |
| 359 | const struct ref *ref; |
| 360 | struct string_list_item *item; |
| 361 | char *signing_key_id = get_signing_key_id(); |
| 362 | char *signing_key = get_signing_key(); |
| 363 | const char *cp, *np; |
| 364 | struct strbuf cert = STRBUF_INIT; |
| 365 | int update_seen = 0; |
| 366 | |
| 367 | strbuf_addstr(&cert, "certificate version 0.1\n"); |
| 368 | strbuf_addf(&cert, "pusher %s ", signing_key_id); |
| 369 | datestamp(&cert); |
| 370 | strbuf_addch(&cert, '\n'); |
| 371 | if (args->url && *args->url) { |
| 372 | char *anon_url = transport_anonymize_url(args->url); |
| 373 | strbuf_addf(&cert, "pushee %s\n", anon_url); |
| 374 | free(anon_url); |
| 375 | } |
| 376 | if (push_cert_nonce[0]) |
| 377 | strbuf_addf(&cert, "nonce %s\n", push_cert_nonce); |
| 378 | if (args->push_options) |
| 379 | for_each_string_list_item(item, args->push_options) |
| 380 | strbuf_addf(&cert, "push-option %s\n", item->string); |
| 381 | strbuf_addstr(&cert, "\n"); |
| 382 | |
| 383 | for (ref = remote_refs; ref; ref = ref->next) { |
| 384 | if (check_to_send_update(ref, args) < 0) |
| 385 | continue; |
| 386 | update_seen = 1; |
| 387 | strbuf_addf(&cert, "%s %s %s\n", |
| 388 | oid_to_hex(&ref->old_oid), |
| 389 | oid_to_hex(&ref->new_oid), |
| 390 | ref->name); |
| 391 | } |
| 392 | if (!update_seen) |
| 393 | goto free_return; |
| 394 | |
| 395 | if (sign_buffer(&cert, &cert, signing_key, 0)) |
| 396 | die(_("failed to sign the push certificate")); |
| 397 | |
| 398 | packet_buf_write(req_buf, "push-cert%c%s", 0, cap_string); |
| 399 | for (cp = cert.buf; cp < cert.buf + cert.len; cp = np) { |
| 400 | np = next_line(cp, cert.buf + cert.len - cp); |
| 401 | packet_buf_write(req_buf, |
| 402 | "%.*s", (int)(np - cp), cp); |
| 403 | } |
| 404 | packet_buf_write(req_buf, "push-cert-end\n"); |
| 405 | |
| 406 | free_return: |
| 407 | free(signing_key_id); |
| 408 | free(signing_key); |
| 409 | strbuf_release(&cert); |
| 410 | return update_seen; |
no test coverage detected