|
Lines 3288-3398
dns_message_dumpsig(dns_message_t *msg, char *txt1) {
Link Here
|
| 3288 |
|
3288 |
|
| 3289 |
isc_result_t |
3289 |
isc_result_t |
| 3290 |
dns_message_checksig(dns_message_t *msg, dns_view_t *view) { |
3290 |
dns_message_checksig(dns_message_t *msg, dns_view_t *view) { |
| 3291 |
isc_buffer_t b, msgb; |
3291 |
isc_buffer_t msgb; |
| 3292 |
|
3292 |
|
| 3293 |
REQUIRE(DNS_MESSAGE_VALID(msg)); |
3293 |
REQUIRE(DNS_MESSAGE_VALID(msg)); |
| 3294 |
|
3294 |
|
| 3295 |
if (msg->tsigkey == NULL && msg->tsig == NULL && msg->sig0 == NULL) { |
3295 |
if (msg->tsigkey == NULL && msg->tsig == NULL) { |
| 3296 |
return (ISC_R_SUCCESS); |
3296 |
return (ISC_R_SUCCESS); |
| 3297 |
} |
3297 |
} |
| 3298 |
|
3298 |
|
| 3299 |
INSIST(msg->saved.base != NULL); |
3299 |
INSIST(msg->saved.base != NULL); |
| 3300 |
isc_buffer_init(&msgb, msg->saved.base, msg->saved.length); |
3300 |
isc_buffer_init(&msgb, msg->saved.base, msg->saved.length); |
| 3301 |
isc_buffer_add(&msgb, msg->saved.length); |
3301 |
isc_buffer_add(&msgb, msg->saved.length); |
| 3302 |
if (msg->tsigkey != NULL || msg->tsig != NULL) { |
|
|
| 3303 |
#ifdef SKAN_MSG_DEBUG |
3302 |
#ifdef SKAN_MSG_DEBUG |
| 3304 |
dns_message_dumpsig(msg, "dns_message_checksig#1"); |
3303 |
dns_message_dumpsig(msg, "dns_message_checksig#1"); |
| 3305 |
#endif /* ifdef SKAN_MSG_DEBUG */ |
3304 |
#endif /* ifdef SKAN_MSG_DEBUG */ |
| 3306 |
if (view != NULL) { |
3305 |
if (view != NULL) { |
| 3307 |
return (dns_view_checksig(view, &msgb, msg)); |
3306 |
return (dns_view_checksig(view, &msgb, msg)); |
| 3308 |
} else { |
|
|
| 3309 |
return (dns_tsig_verify(&msgb, msg, NULL, NULL)); |
| 3310 |
} |
| 3311 |
} else { |
3307 |
} else { |
| 3312 |
dns_rdata_t rdata = DNS_RDATA_INIT; |
3308 |
return (dns_tsig_verify(&msgb, msg, NULL, NULL)); |
| 3313 |
dns_rdata_sig_t sig; |
|
|
| 3314 |
dns_rdataset_t keyset; |
| 3315 |
isc_result_t result; |
| 3316 |
|
| 3317 |
result = dns_rdataset_first(msg->sig0); |
| 3318 |
INSIST(result == ISC_R_SUCCESS); |
| 3319 |
dns_rdataset_current(msg->sig0, &rdata); |
| 3320 |
|
| 3321 |
/* |
| 3322 |
* This can occur when the message is a dynamic update, since |
| 3323 |
* the rdata length checking is relaxed. This should not |
| 3324 |
* happen in a well-formed message, since the SIG(0) is only |
| 3325 |
* looked for in the additional section, and the dynamic update |
| 3326 |
* meta-records are in the prerequisite and update sections. |
| 3327 |
*/ |
| 3328 |
if (rdata.length == 0) { |
| 3329 |
return (ISC_R_UNEXPECTEDEND); |
| 3330 |
} |
| 3331 |
|
| 3332 |
result = dns_rdata_tostruct(&rdata, &sig, NULL); |
| 3333 |
if (result != ISC_R_SUCCESS) { |
| 3334 |
return (result); |
| 3335 |
} |
| 3336 |
|
| 3337 |
dns_rdataset_init(&keyset); |
| 3338 |
if (view == NULL) { |
| 3339 |
result = DNS_R_KEYUNAUTHORIZED; |
| 3340 |
goto freesig; |
| 3341 |
} |
| 3342 |
result = dns_view_simplefind(view, &sig.signer, |
| 3343 |
dns_rdatatype_key /* SIG(0) */, 0, |
| 3344 |
0, false, &keyset, NULL); |
| 3345 |
|
| 3346 |
if (result != ISC_R_SUCCESS) { |
| 3347 |
/* XXXBEW Should possibly create a fetch here */ |
| 3348 |
result = DNS_R_KEYUNAUTHORIZED; |
| 3349 |
goto freesig; |
| 3350 |
} else if (keyset.trust < dns_trust_secure) { |
| 3351 |
/* XXXBEW Should call a validator here */ |
| 3352 |
result = DNS_R_KEYUNAUTHORIZED; |
| 3353 |
goto freesig; |
| 3354 |
} |
| 3355 |
result = dns_rdataset_first(&keyset); |
| 3356 |
INSIST(result == ISC_R_SUCCESS); |
| 3357 |
for (; result == ISC_R_SUCCESS; |
| 3358 |
result = dns_rdataset_next(&keyset)) |
| 3359 |
{ |
| 3360 |
dst_key_t *key = NULL; |
| 3361 |
|
| 3362 |
dns_rdata_reset(&rdata); |
| 3363 |
dns_rdataset_current(&keyset, &rdata); |
| 3364 |
isc_buffer_init(&b, rdata.data, rdata.length); |
| 3365 |
isc_buffer_add(&b, rdata.length); |
| 3366 |
|
| 3367 |
result = dst_key_fromdns(&sig.signer, rdata.rdclass, &b, |
| 3368 |
view->mctx, &key); |
| 3369 |
if (result != ISC_R_SUCCESS) { |
| 3370 |
continue; |
| 3371 |
} |
| 3372 |
if (dst_key_alg(key) != sig.algorithm || |
| 3373 |
dst_key_id(key) != sig.keyid || |
| 3374 |
!(dst_key_proto(key) == DNS_KEYPROTO_DNSSEC || |
| 3375 |
dst_key_proto(key) == DNS_KEYPROTO_ANY)) |
| 3376 |
{ |
| 3377 |
dst_key_free(&key); |
| 3378 |
continue; |
| 3379 |
} |
| 3380 |
result = dns_dnssec_verifymessage(&msgb, msg, key); |
| 3381 |
dst_key_free(&key); |
| 3382 |
if (result == ISC_R_SUCCESS) { |
| 3383 |
break; |
| 3384 |
} |
| 3385 |
} |
| 3386 |
if (result == ISC_R_NOMORE) { |
| 3387 |
result = DNS_R_KEYUNAUTHORIZED; |
| 3388 |
} |
| 3389 |
|
| 3390 |
freesig: |
| 3391 |
if (dns_rdataset_isassociated(&keyset)) { |
| 3392 |
dns_rdataset_disassociate(&keyset); |
| 3393 |
} |
| 3394 |
dns_rdata_freestruct(&sig); |
| 3395 |
return (result); |
| 3396 |
} |
3309 |
} |
| 3397 |
} |
3310 |
} |
| 3398 |
|
3311 |
|