Bug 571574 - NetscapeCookieFile incorrectly using milliseconds
Summary: NetscapeCookieFile incorrectly using milliseconds
Status: RESOLVED FIXED
Alias: None
Product: JGit
Classification: Technology
Component: JGit (show other bugs)
Version: 5.10   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 5.11   Edit
Assignee: Thomas Wolf CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-02-28 16:15 EST by Farid Zakaria CLA
Modified: 2021-03-03 03:39 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Farid Zakaria CLA 2021-02-28 16:15:30 EST
I am trying to use the _cookieFile_ HttpTransport setup introduced in 5.4.0 (https://projects.eclipse.org/projects/technology.jgit/reviews/5.4.0-release-review)

I found that my cookie file is not being used and therefore authentication is failing.

Upon digging into the code, I found this particular line https://github.com/eclipse/jgit/blob/master/org.eclipse.jgit/src/org/eclipse/jgit/internal/transport/http/NetscapeCookieFile.java#L239

```
long expires = Long.parseLong(cookieLineParts[4]);
long maxAge = (expires - creationDate.getTime()) / 1000;
if (maxAge <= 0) {
    return null; // skip expired cookies
}
```

You can see that it's comparing the expires with `creationDate.getTime()` which returns the number of milliseconds since January 1, 1970, 00:00:00 GMT.

According to the CURL documentation that specifies the NetscapeCookie format
https://curl.se/docs/http-cookies.html 

```
Fields in the file
Field number, what type and example data and the meaning of it:

- string example.com - the domain name
- boolean FALSE - include subdomains
- string /foobar/ - path
- boolean TRUE - send/receive over HTTPS only
- number 1462299217 - expires at - seconds since Jan 1st 1970, or 0
- string person - name of the cookie
- string daniel - value of the cookie
```

_expires at_ should be in *seconds*
Comment 1 Eclipse Genie CLA 2021-03-01 02:37:14 EST
New Gerrit change created: https://git.eclipse.org/r/c/jgit/jgit/+/176983