Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
Rdpgw
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirror
Rdpgw
Commits
2954cecb
Commit
2954cecb
authored
4 years ago
by
Bolke de Bruin
Browse files
Options
Downloads
Patches
Plain Diff
Deleted unused files
parent
636e7d54
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
download.go
+0
-112
0 additions, 112 deletions
download.go
with
0 additions
and
112 deletions
download.go
deleted
100644 → 0
+
0
−
112
View file @
636e7d54
package
main
import
(
"encoding/hex"
"encoding/json"
"github.com/patrickmn/go-cache"
"golang.org/x/oauth2"
"log"
"math/rand"
"net/http"
"strings"
"time"
)
const
state
=
"thisismystatebutshouldberandom"
func
handleRdpDownload
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
cookie
,
err
:=
r
.
Cookie
(
"RDPGWSESSIONV1"
)
if
err
!=
nil
{
http
.
Redirect
(
w
,
r
,
oauthConfig
.
AuthCodeURL
(
state
),
http
.
StatusFound
)
return
}
data
,
found
:=
tokens
.
Get
(
cookie
.
Value
)
if
found
==
false
{
log
.
Printf
(
"Found expired or non existent session: %s"
,
cookie
.
Value
)
http
.
Redirect
(
w
,
r
,
oauthConfig
.
AuthCodeURL
(
state
),
http
.
StatusFound
)
return
}
// do a round robin selection for now
rand
.
Seed
(
time
.
Now
()
.
Unix
())
var
host
=
conf
.
Server
.
Hosts
[
rand
.
Intn
(
len
(
conf
.
Server
.
Hosts
))]
for
k
,
v
:=
range
data
.
(
map
[
string
]
interface
{})
{
if
val
,
ok
:=
v
.
(
string
);
ok
==
true
{
host
=
strings
.
Replace
(
host
,
"{{ "
+
k
+
" }}"
,
val
,
1
)
}
}
// authenticated
seed
:=
make
([]
byte
,
16
)
rand
.
Read
(
seed
)
fn
:=
hex
.
EncodeToString
(
seed
)
+
".rdp"
w
.
Header
()
.
Set
(
"Content-Disposition"
,
"attachment; filename="
+
fn
)
w
.
Header
()
.
Set
(
"Content-Type"
,
"application/x-rdp"
)
http
.
ServeContent
(
w
,
r
,
fn
,
time
.
Now
(),
strings
.
NewReader
(
"full address:s:"
+
host
+
"
\r\n
"
+
"gatewayhostname:s:"
+
conf
.
Server
.
GatewayAddress
+
"
\r\n
"
+
"gatewaycredentialssource:i:5
\r\n
"
+
"gatewayusagemethod:i:1
\r\n
"
+
"gatewayprofileusagemethod:i:1
\r\n
"
+
"gatewayaccesstoken:s:"
+
cookie
.
Value
+
"
\r\n
"
))
}
func
handleCallback
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
if
r
.
URL
.
Query
()
.
Get
(
"state"
)
!=
state
{
http
.
Error
(
w
,
"state did not match"
,
http
.
StatusBadRequest
)
return
}
oauthToken
,
err
:=
oauthConfig
.
Exchange
(
ctx
,
r
.
URL
.
Query
()
.
Get
(
"code"
))
if
err
!=
nil
{
http
.
Error
(
w
,
"Failed to exchange token: "
+
err
.
Error
(),
http
.
StatusInternalServerError
)
return
}
rawIDToken
,
ok
:=
oauthToken
.
Extra
(
"id_token"
)
.
(
string
)
if
!
ok
{
http
.
Error
(
w
,
"No id_token field in oauth2 token."
,
http
.
StatusInternalServerError
)
return
}
idToken
,
err
:=
verifier
.
Verify
(
ctx
,
rawIDToken
)
if
err
!=
nil
{
http
.
Error
(
w
,
"Failed to verify ID Token: "
+
err
.
Error
(),
http
.
StatusInternalServerError
)
return
}
resp
:=
struct
{
OAuth2Token
*
oauth2
.
Token
IDTokenClaims
*
json
.
RawMessage
// ID Token payload is just JSON.
}{
oauthToken
,
new
(
json
.
RawMessage
)}
if
err
:=
idToken
.
Claims
(
&
resp
.
IDTokenClaims
);
err
!=
nil
{
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusInternalServerError
)
return
}
var
data
map
[
string
]
interface
{}
if
err
:=
json
.
Unmarshal
(
*
resp
.
IDTokenClaims
,
&
data
);
err
!=
nil
{
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusInternalServerError
)
return
}
seed
:=
make
([]
byte
,
16
)
rand
.
Read
(
seed
)
token
:=
hex
.
EncodeToString
(
seed
)
cookie
:=
http
.
Cookie
{
Name
:
"RDPGWSESSIONV1"
,
Value
:
token
,
Path
:
"/"
,
Secure
:
true
,
HttpOnly
:
true
,
}
// TODO: make dynamic
tokens
.
Set
(
token
,
data
,
cache
.
DefaultExpiration
)
http
.
SetCookie
(
w
,
&
cookie
)
http
.
Redirect
(
w
,
r
,
"/connect"
,
http
.
StatusFound
)
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment