Skip to content

Commit

Permalink
Added link following checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
a-h committed Sep 8, 2020
1 parent 41aae2f commit fdb66bc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
25 changes: 21 additions & 4 deletions browse/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ func main() {
}
redirectCount = 0
if strings.HasPrefix(string(resp.Header.Code), "6") {
msg := fmt.Sprintf("The server has requested a certificate: code %s, meta: %q", resp.Header.Code, resp.Header.Meta)
var meta string
if resp.Header.Meta != "" {
meta = fmt.Sprintf("(%s)", resp.Header.Meta)
}
msg := fmt.Sprintf("The server has requested a certificate.\n\nCode: %s %s", resp.Header.Code, meta)
switch NewOptions(s, msg, "Create (Permanent)", "Create (Temporary)", "Cancel").Focus() {
case "Create (Permanent)":
//TODO: Add a certificate to the permanent store.
Expand Down Expand Up @@ -171,14 +175,27 @@ func main() {
}
next, err := b.Focus()
if err != nil {
//TODO: The link was garbage, show the error.
NewOptions(s, fmt.Sprintf("Invalid link: %v\n", err), "OK").Focus()
askForURL = true
continue
}
if next != nil {
//TODO: Ask the user whether they want to follow it, if it's a non-Gemini link, or goes to a different domain.
urlString = next.String()
// User has selected a link.
if next.Scheme != "gemini" {
if open := NewOptions(s, fmt.Sprintf("Open non-gemini link?\n\n %v", next.String()), "Yes", "No").Focus(); open == "Yes" {
//TODO: Open with the appropriate browser.
urlString = next.String()
askForURL = false
continue
}
}
if next.Host != u.Host {
if open := NewOptions(s, fmt.Sprintf("Follow cross-domain link?\n\n %v", next.String()), "Yes", "No").Focus(); open == "Yes" {
urlString = next.String()
askForURL = false
continue
}
}
askForURL = false
continue
}
Expand Down
3 changes: 2 additions & 1 deletion cert/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ func Generate(organization, commonName, hosts string, duration time.Duration) (c
// KeyUsage bits set in the x509.Certificate template
keyUsage := x509.KeyUsageDigitalSignature

// Give some flexibility to handle clock adjustments.
notBefore := time.Now().Add(time.Hour * -24)
notAfter := notBefore.Add(duration)
notAfter := time.Now().Add(duration)

serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
Expand Down

0 comments on commit fdb66bc

Please sign in to comment.