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

Improve LICENSE + copyright information & CONTRIBUTING file #2556

Merged
merged 5 commits into from
Jan 15, 2025

Conversation

Ana06
Copy link
Member

@Ana06 Ana06 commented Jan 15, 2025

  • Replace LICENSE text file with the official Apache one: https://www.apache.org/licenses/LICENSE-2.0.txt. This changes Copyright (C) 2021 Mandiant, Inc. by the following template language that had been incorrectly replaced: Copyright [yyyy] [name of copyright owner]

  • Improve CLA information to adhere to Google policies (one needed sentence was missing).

  • Use Google's default Code of Conduct for consistency with other Google's projects.

  • Replace the header from source code files. The old header had the confusing sentence All rights reserved, which does not make sense for an open source license. Replace the header by the default Google header that corrects this issue and keep capa consistent with other Google projects. Also replace also the copyright text in the web/public/index.html file for consistency and adapt the linter to work with the new header. The changes in the copyright header have been made with the following script:

    import os
    import re
    
    OLD_HEADER = b"# Copyright \(C\) (?P<year>\d+).* Mandiant, Inc(.|\n)*See the License for the specific language governing permissions and limitations under the License.\n"
    NEW_HEADER = b"""# Copyright %s Google LLC 
    #
    # Licensed under the Apache License, Version 2.0 (the "License");
    # you may not use this file except in compliance with the License.
    # You may obtain a copy of the License at
    #
    #     http://www.apache.org/licenses/LICENSE-2.0
    #
    # Unless required by applicable law or agreed to in writing, software
    # distributed under the License is distributed on an "AS IS" BASIS,
    # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    # See the License for the specific language governing permissions and 
    # limitations under the License.
    
    """ 
    
    for dir_path, dir_names, file_names in os.walk("capa"):
        for file_name in file_names:
            # header are only in `.py` and `.toml` files
            if file_name[-3:] not in (".py", "oml"):
                continue
            file_path = f"{dir_path}/{file_name}"
            f = open(file_path, "rb+")
            content = f.read()
            m = re.search(OLD_HEADER, content)
            if not m:
                continue
            print(f"{file_path}: {m.group('year')}")
            content = content.replace(m.group(0), NEW_HEADER % m.group("year"))
            f.seek(0)
            f.write(content)

    Some files had the copyright headers inside a """ comment and needed manual changes before applying the script. hook-vivisect.py and pyinstaller.spec didn't include the license in the header and also needed manual changes.

  • Add missing headers to the source code files inside the web directory and the capa/render/proto/capa.proto file. I have used addlicense to add the headers. I think it would be a good idea to use addlicense as linter in this project, but I think we should wait until the following issues are resolved (and ensure there are no other issues): Ignore empty files google/addlicense#162, Support spec files google/addlicense#163. I can open an issue after this PR has been merged to propose using addlicense as linter.

Related PRs in other Mandiant repositories: mandiant/flare-vm#638, mandiant/VM-Packages#1238

Checklist

  • No CHANGELOG update needed
  • No new tests needed
  • No documentation update needed

@Ana06 Ana06 added the documentation Improvements or additions to documentation label Jan 15, 2025
@Ana06 Ana06 requested a review from a team January 15, 2025 12:21
@Ana06 Ana06 force-pushed the legal branch 2 times, most recently from 65c76bd to 57aa504 Compare January 15, 2025 12:52
Copy link
Collaborator

@williballenthin williballenthin left a comment

Choose a reason for hiding this comment

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

lgtm, thanks @Ana06!

@williballenthin
Copy link
Collaborator

two things:

  • a few small formatting errors called out by black
  • please recognize yourself in the changelog

Ana06 added 2 commits January 15, 2025 14:28
Replace LICENSE text file with the official Apache one:
https://www.apache.org/licenses/LICENSE-2.0.txt

This changes `Copyright (C) 2021 Mandiant, Inc.` by the following
template language that had been incorrectly replaced:
`Copyright [yyyy] [name of copyright owner]`
Improve CLA information to adhere to Google policies.
Ana06 added 3 commits January 15, 2025 15:52
Use Google's default Code of Conduct for consistency with other Google's
projects.
Replace the header from source code files using the following script:
```Python
for dir_path, dir_names, file_names in os.walk("capa"):
    for file_name in file_names:
        # header are only in `.py` and `.toml` files
        if file_name[-3:] not in (".py", "oml"):
            continue
        file_path = f"{dir_path}/{file_name}"
        f = open(file_path, "rb+")
        content = f.read()
        m = re.search(OLD_HEADER, content)
        if not m:
            continue
        print(f"{file_path}: {m.group('year')}")
        content = content.replace(m.group(0), NEW_HEADER % m.group("year"))
        f.seek(0)
        f.write(content)
```

Some files had the copyright headers inside a `"""` comment and needed
manual changes before applying the script. `hook-vivisect.py` and
`pyinstaller.spec` didn't include the license in the header and also
needed manual changes.

The old header had the confusing sentence `All rights reserved`, which
does not make sense for an open source license. Replace the header by
the default Google header that corrects this issue and keep capa
consistent with other Google projects.

Adapt the linter to work with the new header.

Replace also the copyright text in the `web/public/index.html` file for
consistency.
Add copyright and license information headers to the source code files
inside the `web` directory and the `capa/render/proto/capa.proto` file.
I have used addlicense to add the headers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants