zrhoffman commented on code in PR #7110: URL: https://github.com/apache/trafficcontrol/pull/7110#discussion_r1131408827
########## experimental/certificate_auth/certs/generate_certs.go: ########## @@ -0,0 +1,446 @@ +package main + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import ( + "bytes" + "crypto/rand" + "crypto/rsa" + "crypto/x509" + "crypto/x509/pkix" + "encoding/asn1" + "encoding/pem" + "flag" + "fmt" + "io/ioutil" + "log" + "math" + "math/big" + "net" + "time" +) + +// CertificateKeyPair contains the parsed representation of a certificate +// and private key. +type CertificateKeyPair struct { + Certificate *x509.Certificate + PrivateKey *rsa.PrivateKey +} + +// CertificatePEMPair contains the PEM encoded certificate and private key. +type CertificatePEMPair struct { + CertificatePEM, PrivateKeyPEM string +} + +var ( + rootCN = "root.local" + interCN = "intermediate.local" + clientCN = "client.local" + serverCN = "server.local" + + uid = "userid" + // useEcdsa = false //TODO: Enable and refactor +) + +func main() { + flag.StringVar(&uid, "uid", uid, "[Optional] The User ID value to be added to the client certificate") + // flag.BoolVar(&useEcdsa, "useEcdsa", useEcdsa, "[Optional] Use ECDSA 256 when generating the keys. Default is RSA 4096") Review Comment: Fixed in #7110 ########## experimental/certificate_auth/example/client/client.go: ########## @@ -0,0 +1,79 @@ +package main + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import ( + "bytes" + "crypto/tls" + "fmt" + "io/ioutil" + "log" + "net/http" + "time" +) + +func main() { + // LoadX509KeyPair can also load certificate chain with intermediates + cert, _ := tls.LoadX509KeyPair("../certs/client-intermediate-chain.crt.pem", "../certs/client.key.pem") + + transport := &http.Transport{ + TLSClientConfig: &tls.Config{ + Certificates: []tls.Certificate{cert}, + }, + } + + client := http.Client{ + Timeout: time.Second * 60, + Transport: transport, + } + + // Send standard username/password form combo + // reqBody, err := json.Marshal(map[string]string{ + // "u": "userid", + // "p": "exampleuseridpassword", + // }) + // if err != nil { + // log.Fatalln(err) + // } Review Comment: Fixed in #7110 ########## experimental/certificate_auth/example/client/client.go: ########## @@ -0,0 +1,79 @@ +package main + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import ( + "bytes" + "crypto/tls" + "fmt" + "io/ioutil" + "log" + "net/http" + "time" +) + +func main() { + // LoadX509KeyPair can also load certificate chain with intermediates + cert, _ := tls.LoadX509KeyPair("../certs/client-intermediate-chain.crt.pem", "../certs/client.key.pem") + + transport := &http.Transport{ + TLSClientConfig: &tls.Config{ + Certificates: []tls.Certificate{cert}, + }, + } + + client := http.Client{ + Timeout: time.Second * 60, + Transport: transport, + } + + // Send standard username/password form combo + // reqBody, err := json.Marshal(map[string]string{ + // "u": "userid", + // "p": "exampleuseridpassword", + // }) + // if err != nil { + // log.Fatalln(err) + // } + + req, err := http.NewRequest( + http.MethodPost, + "https://server.local:8443/api/4.0/user/login", + bytes.NewBufferString(""), + // bytes.NewBuffer(reqBody), // username/password Review Comment: Fixed in #7110 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
