}
/*
- * Found the cache entry, use the calculated PMK.
+ * No provided PSK. Try to look it up in the cache. If
+ * it isn't there, find it in the config items.
*/
- if (inst->cache && mac) {
- rlm_dpsk_cache_t *entry;
+ if (!psk) {
+ if (inst->cache && mac) {
+ rlm_dpsk_cache_t *entry;
- entry = dpsk_cache_find(request, inst, buffer, buflen, ssid, mac);
- if (entry) {
- memcpy(buffer, entry->pmk, buflen);
- return 1;
- }
- RDEBUG3("Cache entry not found");
- } /* else no caching */
+ entry = dpsk_cache_find(request, inst, buffer, buflen, ssid, mac);
+ if (entry) {
+ memcpy(buffer, entry->pmk, buflen);
+ return 1;
+ }
+ RDEBUG3("Cache entry not found");
+ } /* else no caching */
- if (!psk) {
vp = fr_pair_find_by_num(request->config, PW_PRE_SHARED_KEY, 0, TAG_ANY);
if (!vp) {
RDEBUG("No &config:Pre-Shared-Key");
rlm_dpsk_t *inst = instance;
VALUE_PAIR *anonce, *key_msg, *ssid, *vp;
rlm_dpsk_cache_t *entry;
- int lineno;
- size_t len;
+ int lineno = 0;
+ size_t len, psk_len;
unsigned int digest_len, mic_len;
eapol_attr_t const *eapol;
eapol_attr_t *zeroed;
FILE *fp = NULL;
- char const *psk_identity = NULL;
+ char const *psk_identity = NULL, *psk;
uint8_t *p;
uint8_t const *snonce, *ap_mac;
uint8_t const *min_mac, *max_mac;
vp = fr_pair_find_by_num(request->config, PW_PSK_IDENTITY, 0, TAG_ANY);
if (vp) psk_identity = vp->vp_strvalue;
+ vp = fr_pair_find_by_num(request->config, PW_PRE_SHARED_KEY, 0, TAG_ANY);
+ if (vp) {
+ psk = vp->vp_strvalue;
+ psk_len = vp->vp_length;
+ } else {
+ psk = NULL;
+ psk_len = 0;
+ }
+
/*
* Get the AP MAC address.
*/
*p = '\0';
fr_assert(sizeof(message) == (p + 1 - message));
- if (inst->filename) {
+ if (inst->filename && !psk) {
FR_TOKEN token;
char const *q;
char token_psk[256];
return RLM_MODULE_FAIL;
}
- lineno = 0;
-
get_next_psk:
q = fgets(buffer, sizeof(buffer), fp);
if (!q) {
*/
vp = fr_pair_find_by_num(request->config, PW_PAIRWISE_MASTER_KEY, 0, TAG_ANY);
if (!vp) {
- if (generate_pmk(request, inst, pmk, sizeof(pmk), ssid, s_mac, NULL, 0) == 0) {
+ if (generate_pmk(request, inst, pmk, sizeof(pmk), ssid, s_mac, psk, psk_len) == 0) {
RDEBUG("No &config:Pairwise-Master-Key or &config:Pre-Shared-Key found");
fr_assert(!fp);
return RLM_MODULE_NOOP;
RDEBUG3("Cache entry saved");
}
entry->expires = request->timestamp + inst->cache_lifetime;
+
/*
* Add the PSK to the reply items, if it was cached.
*/