Skip to content

Commit

Permalink
feat (read packet): better error for TLS attempt on non-TLS conn
Browse files Browse the repository at this point in the history
  • Loading branch information
jimlambrt committed May 1, 2023
1 parent 4e73db4 commit 2ad3888
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,11 @@ func (c *conn) readPacket(requestID int) (*packet, error) {
c.mu.Lock()
defer c.mu.Unlock()
berPacket, err := ber.ReadPacket(c.reader)
if err != nil {
return nil, fmt.Errorf("%s: error reading ber packet for %d/%d: %w", op, c.connID, requestID, err)
switch {
case err != nil && strings.Contains(err.Error(), "invalid character for IA5String at pos 2"):
return nil, fmt.Errorf("%s: error reading ber packet for %d/%d (possible attempt to use TLS with a non-TLS server): %w", op, c.connID, requestID, err)
case err != nil:
return nil, fmt.Errorf("%s: error reading ber packet for %d/%d: %w", op, c.connID, requestID, err)
}
return berPacket, nil
}()
Expand Down

0 comments on commit 2ad3888

Please sign in to comment.