-
Notifications
You must be signed in to change notification settings - Fork 341
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This supports encrypted or signed RPC communication with the namenode, and brings us one step closer to full KRB support.
- Loading branch information
Showing
8 changed files
with
299 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package rpc | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
"strings" | ||
|
||
hadoop "github.com/colinmarc/hdfs/v2/internal/protocol/hadoop_common" | ||
) | ||
|
||
const ( | ||
// qopAuthenication is how the namenode refers to authentication mode, which | ||
// only establishes mutual authentication without encryption (the default). | ||
qopAuthentication = "auth" | ||
// qopIntegrity is how the namenode refers to integrity mode, which, in | ||
// in addition to authentication, verifies the signature of RPC messages. | ||
qopIntegrity = "auth-int" | ||
// qopPrivacy is how the namenode refers to privacy mode, which, in addition | ||
// to authentication and integrity, provides full end-to-end encryption for | ||
// RPC messages. | ||
qopPrivacy = "auth-conf" | ||
) | ||
|
||
var challengeRegexp = regexp.MustCompile(",?([a-zA-Z0-9]+)=(\"([^\"]+)\"|([^,]+)),?") | ||
|
||
type tokenChallenge struct { | ||
realm string | ||
nonce string | ||
qop string | ||
charset string | ||
cipher []string | ||
algorithm string | ||
} | ||
|
||
// parseChallenge returns a tokenChallenge parsed from a challenge response from | ||
// the namenode. | ||
func parseChallenge(auth *hadoop.RpcSaslProto_SaslAuth) (*tokenChallenge, error) { | ||
tokenChallenge := tokenChallenge{} | ||
|
||
matched := challengeRegexp.FindAllSubmatch(auth.Challenge, -1) | ||
if matched == nil { | ||
return nil, fmt.Errorf("invalid token challenge: %s", auth.Challenge) | ||
} | ||
|
||
for _, m := range matched { | ||
key := string(m[1]) | ||
val := string(m[3]) | ||
switch key { | ||
case "realm": | ||
tokenChallenge.realm = val | ||
case "nonce": | ||
tokenChallenge.nonce = val | ||
case "qop": | ||
tokenChallenge.qop = val | ||
case "charset": | ||
tokenChallenge.charset = val | ||
case "cipher": | ||
tokenChallenge.cipher = strings.Split(val, ",") | ||
case "algorithm": | ||
tokenChallenge.algorithm = val | ||
default: | ||
} | ||
} | ||
|
||
return &tokenChallenge, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.