Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added obfuscation for keys #67

Merged
merged 7 commits into from Jul 24, 2019
Merged

Added obfuscation for keys #67

merged 7 commits into from Jul 24, 2019

Conversation

rmirabelli
Copy link
Contributor

Simple obfuscation, documentation included.

let key = ObfuscationKey().a.b.c.n1.n2.n3.value

@CLAassistant
Copy link

CLAassistant commented Jul 23, 2019

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@tylermilner tylermilner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good. Mostly minor suggestions. Also need to get a CHANGELOG entry added.

// UtiliKit-iOS
//
// Created by Russell Mirabelli on 7/23/19.
// Copyright © 2019 CocoaPods. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we need to update the copyright here to "Bottle Rocket Studios". Could you go ahead and update this comment and make the change in the project file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


var value: String {
get {
return _value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use the implicit getter here instead of manually specifying the get block.

var value: String {
    return _value
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

//

import XCTest
@testable import UtiliKit
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking a regular import might work just as well here since we're testing public APIs (also, we might need to make much ObfuscatedKey.swift public so that it's usable in client code).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

func testSimpleObfuscatedString() {
let key = ObfuscatedKey().A.B.A.B.value
let expected = "ABAB"
XCTAssert(key == expected, "Keys do not match: \(key) is not \(expected)")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very minor, but you might consider using XCTAssertEqual() instead of the more generic XCTAssert().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}

func testExtras() {
let key = ObfuscatedKey().dot.dash.underscore.anything("=").value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very minor, but we might consider renaming anything(_:) to read a little better here at the call site. Some potential suggestions:

  • appending(_:)
  • explicit(_:)
  • extra(_:)
  • additional(_:)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about literal(_:) ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kinda like additional. What about calling it add?
add(_:)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used literal.

@codecov-io
Copy link

codecov-io commented Jul 23, 2019

Codecov Report

Merging #67 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master    #67   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           4      5    +1     
  Lines         413    433   +20     
=====================================
+ Hits          413    433   +20
Impacted Files Coverage Δ
Tests/ObfuscationTests.swift 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2a4f4dc...5d7aca1. Read the comment docs.

Copy link
Contributor

@wmcginty wmcginty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, a few minor changes. Seems like a very useful addition.

/// By using the ObfuscatedKey struct, you can build a human-readable key that nonetheless
/// will not appear simply by running "strings" against your compiled code, and will even
/// not appear as a string within your source code.
struct ObfuscatedKey {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will need to be public.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

}

// codebeat:disable[TOO_MANY_FUNCTIONS]
var A: ObfuscatedKey { return ObfuscatedKey(_value + "A") }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might make sense to throw these into a public extension to alleviate the need to define each of these as public var ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice way to avoid all the publics. Done, and thanks!

}

func testExtras() {
let key = ObfuscatedKey().dot.dash.underscore.anything("=").value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about literal(_:) ?

/// will not appear simply by running "strings" against your compiled code, and will even
/// not appear as a string within your source code.
struct ObfuscatedKey {
private let _value: String
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we lose the internal variable and use public private(set) value: String ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not available on a "let"; I believe that the immutability of a "let" is important to make the general builder technique make sense.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point - withdrawn.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't help but feel like I'm missing something here - what does the private let _value: String and public var value { return _value } get us here over a single immutable public let value. As far as I can tell, we aren't mutating it or validating internally and the same-file extensions should have the same access regardless.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point. Since my merge is still blocked by the license (ugh), I'll think about this and see if there is a good reason I can find.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed, changed.

wmcginty
wmcginty previously approved these changes Jul 23, 2019
tylermilner
tylermilner previously approved these changes Jul 23, 2019
CHANGELOG.md Outdated
@@ -2,6 +2,10 @@

##### Enhancements

* Added obfuscation for keys/passwords to ensure that they don't appear in plaintext.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very minor, maybe just mention the "Obfuscation" subspec and the ObfuscatedKey class so that clients can get a general sense of how they can make use of this new feature when they see these release notes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

earlgaspard
earlgaspard previously approved these changes Jul 23, 2019
@rmirabelli rmirabelli merged commit 264d7eb into BottleRocketStudios:master Jul 24, 2019
@rmirabelli rmirabelli deleted the feature/obfuscation branch July 24, 2019 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants