@@ -29,7 +29,7 @@ extern VALUE rb_cRuggedRepo;
29
29
extern VALUE rb_eRuggedError ;
30
30
VALUE rb_cRuggedRemote ;
31
31
32
- #define RUGGED_REMOTE_CALLBACKS_INIT {1, progress_cb, NULL, credentials_cb, NULL , transfer_progress_cb, update_tips_cb, NULL, NULL, push_update_reference_cb, NULL}
32
+ #define RUGGED_REMOTE_CALLBACKS_INIT {1, progress_cb, NULL, credentials_cb, certificate_check_cb , transfer_progress_cb, update_tips_cb, NULL, NULL, push_update_reference_cb, NULL}
33
33
34
34
static int progress_cb (const char * str , int len , void * data )
35
35
{
@@ -96,6 +96,27 @@ static int update_tips_cb(const char *refname, const git_oid *src, const git_oid
96
96
return payload -> exception ? GIT_ERROR : GIT_OK ;
97
97
}
98
98
99
+ static int certificate_check_cb (git_cert * cert , int valid , const char * host , void * data )
100
+ {
101
+ struct rugged_remote_cb_payload * payload = data ;
102
+ VALUE args = rb_ary_new2 (3 );
103
+ VALUE ret ;
104
+
105
+ if (NIL_P (payload -> certificate_check ))
106
+ return valid ? 0 : GIT_ECERTIFICATE ;
107
+
108
+ rb_ary_push (args , payload -> certificate_check );
109
+ rb_ary_push (args , INT2FIX (valid ));
110
+ rb_ary_push (args , rb_str_new_utf8 (host ));
111
+
112
+ ret = rb_protect (rugged__block_yield_splat , args , & payload -> exception );
113
+
114
+ if (payload -> exception )
115
+ return GIT_ERROR ;
116
+
117
+ return rugged_parse_bool (ret ) ? GIT_OK : GIT_ECERTIFICATE ;
118
+ }
119
+
99
120
struct extract_cred_args
100
121
{
101
122
VALUE rb_callback ;
@@ -174,6 +195,7 @@ void rugged_remote_init_callbacks_and_payload_from_options(
174
195
memcpy (callbacks , & prefilled , sizeof (git_remote_callbacks ));
175
196
176
197
if (!NIL_P (rb_options )) {
198
+ CALLABLE_OR_RAISE (payload -> certificate_check , rb_options , "certificate_check" );
177
199
CALLABLE_OR_RAISE (payload -> update_tips , rb_options , "update_tips" );
178
200
CALLABLE_OR_RAISE (payload -> progress , rb_options , "progress" );
179
201
CALLABLE_OR_RAISE (payload -> transfer_progress , rb_options , "transfer_progress" );
@@ -274,7 +296,7 @@ static VALUE rb_git_remote_ls(int argc, VALUE *argv, VALUE self)
274
296
git_strarray custom_headers = {0 };
275
297
const git_remote_head * * heads ;
276
298
277
- struct rugged_remote_cb_payload payload = { Qnil , Qnil , Qnil , Qnil , Qnil , Qnil , 0 };
299
+ struct rugged_remote_cb_payload payload = { Qnil , Qnil , Qnil , Qnil , Qnil , Qnil , Qnil , 0 };
278
300
279
301
VALUE rb_options ;
280
302
@@ -471,7 +493,7 @@ static VALUE rb_git_remote_check_connection(int argc, VALUE *argv, VALUE self)
471
493
git_remote * remote ;
472
494
git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT ;
473
495
git_strarray custom_headers = {0 };
474
- struct rugged_remote_cb_payload payload = { Qnil , Qnil , Qnil , Qnil , Qnil , Qnil , 0 };
496
+ struct rugged_remote_cb_payload payload = { Qnil , Qnil , Qnil , Qnil , Qnil , Qnil , Qnil , 0 };
475
497
VALUE rb_direction , rb_options ;
476
498
ID id_direction ;
477
499
int error , direction ;
@@ -537,6 +559,11 @@ static VALUE rb_git_remote_check_connection(int argc, VALUE *argv, VALUE self)
537
559
* A callback that will be executed each time a reference is updated locally. It will be
538
560
* passed the +refname+, +old_oid+ and +new_oid+.
539
561
*
562
+ * :certificate_check ::
563
+ * A callback that will be executed each time we validate a certificate using https. It
564
+ * will be passed the +valid+, +host_name+ and the callback should return a true/false to
565
+ * indicate if the certificate has been validated.
566
+ *
540
567
* :message ::
541
568
* The message to insert into the reflogs. Defaults to "fetch".
542
569
*
@@ -559,7 +586,7 @@ static VALUE rb_git_remote_fetch(int argc, VALUE *argv, VALUE self)
559
586
git_strarray refspecs ;
560
587
git_fetch_options opts = GIT_FETCH_OPTIONS_INIT ;
561
588
const git_transfer_progress * stats ;
562
- struct rugged_remote_cb_payload payload = { Qnil , Qnil , Qnil , Qnil , Qnil , Qnil , 0 };
589
+ struct rugged_remote_cb_payload payload = { Qnil , Qnil , Qnil , Qnil , Qnil , Qnil , Qnil , 0 };
563
590
564
591
char * log_message = NULL ;
565
592
int error ;
@@ -650,7 +677,7 @@ static VALUE rb_git_remote_push(int argc, VALUE *argv, VALUE self)
650
677
651
678
int error = 0 ;
652
679
653
- struct rugged_remote_cb_payload payload = { Qnil , Qnil , Qnil , Qnil , Qnil , rb_hash_new (), 0 };
680
+ struct rugged_remote_cb_payload payload = { Qnil , Qnil , Qnil , Qnil , Qnil , Qnil , rb_hash_new (), 0 };
654
681
655
682
rb_scan_args (argc , argv , "01:" , & rb_refspecs , & rb_options );
656
683
0 commit comments