SmartCertificateCheck calls the certificate check for this transport.
(cert *Certificate, valid bool, hostname string)
| 120 | |
| 121 | // SmartCertificateCheck calls the certificate check for this transport. |
| 122 | func (t *Transport) SmartCertificateCheck(cert *Certificate, valid bool, hostname string) error { |
| 123 | var ccert *C.git_cert |
| 124 | switch cert.Kind { |
| 125 | case CertificateHostkey: |
| 126 | chostkeyCert := C.git_cert_hostkey{ |
| 127 | parent: C.git_cert{ |
| 128 | cert_type: C.GIT_CERT_HOSTKEY_LIBSSH2, |
| 129 | }, |
| 130 | _type: C.git_cert_ssh_t(cert.Kind), |
| 131 | hostkey: (*C.char)(C.CBytes(cert.Hostkey.Hostkey)), |
| 132 | hostkey_len: C.size_t(len(cert.Hostkey.Hostkey)), |
| 133 | } |
| 134 | defer C.free(unsafe.Pointer(chostkeyCert.hostkey)) |
| 135 | C.memcpy(unsafe.Pointer(&chostkeyCert.hash_md5[0]), unsafe.Pointer(&cert.Hostkey.HashMD5[0]), C.size_t(len(cert.Hostkey.HashMD5))) |
| 136 | C.memcpy(unsafe.Pointer(&chostkeyCert.hash_sha1[0]), unsafe.Pointer(&cert.Hostkey.HashSHA1[0]), C.size_t(len(cert.Hostkey.HashSHA1))) |
| 137 | C.memcpy(unsafe.Pointer(&chostkeyCert.hash_sha256[0]), unsafe.Pointer(&cert.Hostkey.HashSHA256[0]), C.size_t(len(cert.Hostkey.HashSHA256))) |
| 138 | if cert.Hostkey.SSHPublicKey.Type() == "ssh-rsa" { |
| 139 | chostkeyCert.raw_type = C.GIT_CERT_SSH_RAW_TYPE_RSA |
| 140 | } else if cert.Hostkey.SSHPublicKey.Type() == "ssh-dss" { |
| 141 | chostkeyCert.raw_type = C.GIT_CERT_SSH_RAW_TYPE_DSS |
| 142 | } else { |
| 143 | chostkeyCert.raw_type = C.GIT_CERT_SSH_RAW_TYPE_UNKNOWN |
| 144 | } |
| 145 | ccert = (*C.git_cert)(unsafe.Pointer(&chostkeyCert)) |
| 146 | |
| 147 | case CertificateX509: |
| 148 | cx509Cert := C.git_cert_x509{ |
| 149 | parent: C.git_cert{ |
| 150 | cert_type: C.GIT_CERT_X509, |
| 151 | }, |
| 152 | len: C.size_t(len(cert.X509.Raw)), |
| 153 | data: C.CBytes(cert.X509.Raw), |
| 154 | } |
| 155 | defer C.free(cx509Cert.data) |
| 156 | ccert = (*C.git_cert)(unsafe.Pointer(&cx509Cert)) |
| 157 | } |
| 158 | |
| 159 | runtime.LockOSThread() |
| 160 | defer runtime.UnlockOSThread() |
| 161 | |
| 162 | chostname := C.CString(hostname) |
| 163 | defer C.free(unsafe.Pointer(chostname)) |
| 164 | |
| 165 | cvalid := C.int(0) |
| 166 | if valid { |
| 167 | cvalid = C.int(1) |
| 168 | } |
| 169 | |
| 170 | ret := C.git_transport_smart_certificate_check(t.ptr, ccert, cvalid, chostname) |
| 171 | if ret != 0 { |
| 172 | return MakeGitError(ret) |
| 173 | } |
| 174 | |
| 175 | return nil |
| 176 | } |
| 177 | |
| 178 | // SmartSubtransport is the interface for custom subtransports which carry data |
| 179 | // for the smart transport. |
no test coverage detected